public function createUserAction()
 {
     if (!empty($this->getApp()->JSONBody) && $this->validateUserData($this->getApp()->JSONBody)) {
         $name = $this->getApp()->JSONBody['name'];
         $username = $this->getApp()->JSONBody['username'];
         $password = $this->getApp()->JSONBody['password'];
         $email = $this->getApp()->JSONBody['email'];
         $salt = mcrypt_create_iv(32);
         $user = new User($this->getConfig()['db']);
         $createUser = $user->set(['username' => $username, 'password' => hash('sha256', $password . $salt), 'salt' => $salt, 'name' => $name, 'email' => $email, 'joined' => date('Y-m-d H:i:s'), 'user_group' => 0]);
         $this->getApp()->render(200, ['response' => $createUser]);
     } else {
         $errors = array_map([$this, 'translate'], $this->errors);
         $this->getApp()->render(200, ['response' => $errors, 'error' => true]);
     }
 }
 public function verifyAction()
 {
     if ($this->getApp()->request->isPost()) {
         $user = new User($this->getConfig()['db']);
         $login = $this->getApp()->JSONBody['name'];
         $password = $this->getApp()->JSONBody['pass'];
         $result = false;
         $payload = $user->get('password', ['username' => $login]);
         if (!empty($payload)) {
             list($row) = $payload;
             if ($password === $row['password']) {
                 $result = true;
             }
         }
         $this->getApp()->render(200, ['response' => $result]);
     }
 }
Beispiel #3
0
 protected function toArray(User $user)
 {
     return ['username' => $user->getUsername(), 'email' => $user->getEmail(), 'password' => $user->getPassword(), 'credentials' => json_encode($user->allCredential()), 'role' => json_encode($user->getRoles()), 'token' => $user->getToken()];
 }