| 
									
										
										
										
											2018-07-24 19:31:43 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This is executed inside DatabaseMigrationService class/context
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | $db = $this->getDatabaseService()->GetDbConnection(); | 
					
						
							| 
									
										
										
										
											2018-07-24 19:31:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 20:20:09 +02:00
										 |  |  | if (defined('GROCY_HTTP_USER')) | 
					
						
							| 
									
										
										
										
											2018-07-24 19:31:43 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	// Migrate old user defined in config file to database
 | 
					
						
							| 
									
										
										
										
											2021-07-03 17:46:47 +02:00
										 |  |  | 	$newUserRow = $db->users()->createRow([ | 
					
						
							| 
									
										
										
										
											2018-07-25 20:20:09 +02:00
										 |  |  | 		'username' => GROCY_HTTP_USER, | 
					
						
							|  |  |  | 		'password' => password_hash(GROCY_HTTP_PASSWORD, PASSWORD_DEFAULT) | 
					
						
							| 
									
										
										
										
											2021-07-03 17:46:47 +02:00
										 |  |  | 	]); | 
					
						
							| 
									
										
										
										
											2018-07-24 19:31:43 +02:00
										 |  |  | 	$newUserRow->save(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Create default user "admin" with password "admin"
 | 
					
						
							| 
									
										
										
										
											2021-07-03 17:46:47 +02:00
										 |  |  | 	$newUserRow = $db->users()->createRow([ | 
					
						
							| 
									
										
										
										
											2018-07-24 19:31:43 +02:00
										 |  |  | 		'username' => 'admin', | 
					
						
							|  |  |  | 		'password' => password_hash('admin', PASSWORD_DEFAULT) | 
					
						
							| 
									
										
										
										
											2021-07-03 17:46:47 +02:00
										 |  |  | 	]); | 
					
						
							| 
									
										
										
										
											2018-07-24 19:31:43 +02:00
										 |  |  | 	$newUserRow->save(); | 
					
						
							|  |  |  | } |