| @@ 77-113 (lines=37) @@ | ||
| 74 | * |
|
| 75 | * @return boolean true if okey, false if something went wrong. |
|
| 76 | */ |
|
| 77 | public function callbackSubmit() |
|
| 78 | { |
|
| 79 | // Get values from the submitted form |
|
| 80 | ||
| 81 | $acronym = $this->form->value("acronym"); |
|
| 82 | $password = $this->form->value("password"); |
|
| 83 | $passwordAgain = $this->form->value("password-again"); |
|
| 84 | $email = $this->form->value("email"); |
|
| 85 | $role = $this->form->value("role"); |
|
| 86 | ||
| 87 | // Check password matches |
|
| 88 | if ($password !== $passwordAgain) { |
|
| 89 | $this->form->rememberValues(); |
|
| 90 | $this->form->addOutput("Password did not match."); |
|
| 91 | return false; |
|
| 92 | } |
|
| 93 | ||
| 94 | // Save to database |
|
| 95 | // $db = $this->di->get("db"); |
|
| 96 | // $password = password_hash($password, PASSWORD_DEFAULT); |
|
| 97 | // $db->connect() |
|
| 98 | // ->insert("User", ["acronym", "password"]) |
|
| 99 | // ->execute([$acronym, $password]); |
|
| 100 | $user = new User(); |
|
| 101 | $user->setDb($this->di->get("db")); |
|
| 102 | $user->acronym = $acronym; |
|
| 103 | $user->email = $email; |
|
| 104 | $user->role = $role; |
|
| 105 | // create gravatar from email |
|
| 106 | $gravatar = $user->gravatar($email); |
|
| 107 | $user->gravatar = $gravatar; |
|
| 108 | ||
| 109 | $user->setPassword($password); |
|
| 110 | $user->save(); |
|
| 111 | ||
| 112 | $this->form->addOutput("User was created."); |
|
| 113 | return true; |
|
| 114 | } |
|
| 115 | } |
|
| 116 | ||
| @@ 79-118 (lines=40) @@ | ||
| 76 | * |
|
| 77 | * @return boolean true if okey, false if something went wrong. |
|
| 78 | */ |
|
| 79 | public function callbackSubmit() |
|
| 80 | { |
|
| 81 | // Get values from the submitted form |
|
| 82 | $id = $this->form->value("id"); |
|
| 83 | $acronym = $this->form->value("acronym"); |
|
| 84 | $password = $this->form->value("password"); |
|
| 85 | $passwordAgain = $this->form->value("password-again"); |
|
| 86 | $email = $this->form->value("email"); |
|
| 87 | ||
| 88 | // Check password matches |
|
| 89 | if ($password !== $passwordAgain) { |
|
| 90 | $this->form->rememberValues(); |
|
| 91 | $this->form->addOutput("Password did not match."); |
|
| 92 | return false; |
|
| 93 | } |
|
| 94 | ||
| 95 | // Save to database |
|
| 96 | // $db = $this->di->get("db"); |
|
| 97 | // $password = password_hash($password, PASSWORD_DEFAULT); |
|
| 98 | // $db->connect() |
|
| 99 | // ->insert("User", ["acronym", "password"]) |
|
| 100 | // ->execute([$acronym, $password]); |
|
| 101 | $user = new User(); |
|
| 102 | $user->setDb($this->di->get("db")); |
|
| 103 | ||
| 104 | $user->acronym = $acronym; |
|
| 105 | $user->email = $email; |
|
| 106 | $user->id = $id; |
|
| 107 | $user->role = 1; |
|
| 108 | ||
| 109 | // create/update gravatar from email |
|
| 110 | $gravatar = $user->gravatar($email); |
|
| 111 | $user->gravatar = $gravatar; |
|
| 112 | ||
| 113 | $user->setPassword($password); |
|
| 114 | $user->save(); |
|
| 115 | ||
| 116 | $this->form->addOutput("Användarprofil uppdaterades."); |
|
| 117 | return true; |
|
| 118 | } |
|
| 119 | } |
|
| 120 | ||