Exemple #1
0
 /**
  * Use this function for authenticated member and ustadz
  * if the authenticated is failure, the user will be redirect to
  * warning page that they can input username and pass again
  *
  * @param $username : username user
  * @param $password : password user
  * @return bool
  */
 public static function auth($username, $password)
 {
     $data = Accounts::find(['username' => $username, 'password' => md5($password)]);
     if ($data) {
         # validate was successed
         # Set a session ID
         $account = array($data['id'], $data['username'], $data['name'], $data['type']);
         $session = new Session();
         $session->set('id_account', implode('|', $account));
         return TRUE;
     }
     # validate was failure
     return FALSE;
 }
 public static function edit()
 {
     # login required decorator
     self::login_required();
     # if user perform the form submit button
     if ("POST" == Request::method()) {
         $id = Request::user()->id;
         $name = Request::POST()->name;
         $username = Request::POST()->username;
         $bio = Request::POST()->bio;
         $profile_picture = File::upload('img', 'change_photo');
         $member = Accounts::find(['username' => $username]);
         if ($member and $member['username'] !== Request::user()->username) {
             Session::push('flash-message-form', 'That username has used by other member, please use another!');
             Response::redirect('profile/' . Request::user()->username);
         }
         if ($profile_picture) {
             Accounts::edit($id, $name, $username, $bio, $profile_picture);
         } else {
             Accounts::edit($id, $name, $username, $bio);
         }
         # push a flash message
         Session::push('flash-message', 'Your profile biodata has changed successfully!');
         # if username or name has changed
         # reconfigure the member session data
         if ($name !== Request::user()->name or $username !== Request::user()->username) {
             # get member data by id
             $data = Accounts::findByPK($id);
             # Set a session ID
             $account = array($data['id'], $data['username'], $data['name'], $data['type']);
             $session = new Session();
             $session->set('id_account', implode('|', $account));
         }
         # redirect member profile page
         Response::redirect('profile/' . Request::user()->username);
     } else {
         # redirect to home
         Response::redirect('');
     }
 }