public function post()
 {
     if (!isset($this->post['username'], $this->post['password'])) {
         $this->message = "Missing one or more required parameters";
         $this->status = 400;
         return;
     }
     if (User::idByUsername($this->post['username'])) {
         $this->message = "User already exists";
         $this->status = 400;
         return;
     }
     $user = new User();
     $user->username = $this->post['username'];
     $user->setPassword($this->post['password']);
     $user->save();
     Session::login($user->id);
     $this->message = "User created";
     $this->status = 201;
     $this->response[$this->slug][] = $user->apiData();
 }
Example #2
0
 public static function login($userID)
 {
     $user = new User($userID);
     self::$user = $user->apiData(API_SELF, $userID);
 }