Guest User

Untitled

a guest
Mar 30th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?php
  2.  
  3. class IndexController extends Controller {
  4.    
  5.    
  6.     public function _init() {
  7.         $this->layout->name = "Index";
  8.         if (!checkLogged()) {
  9.             $this->_redirect(BASE_URL . 'signin');
  10.         }
  11.     }
  12.  
  13.     public function changePasswordAction() {
  14. //         don't need create layout
  15.         $this->setNoRender();
  16.  
  17.         $password = trim($_POST['current_pass']);
  18.         $new_password = trim($_POST['new_pass']);
  19.         $repeat_new_password = trim($_POST['repeat_pass']);
  20.  
  21.         $user_id = $_SESSION['user'][id];
  22.         $model_user = new Model_Azuser();
  23.         $oneUser = $model_user->findOneUser($user_id);
  24.         if ($_POST) {
  25.             if (md5($password) === $oneUser['password']) {
  26.                 if (strlen($new_password) >= 6 && strlen($new_password) <= 100) {
  27.                     if ($new_password == $repeat_new_password) {
  28.                         $data = array(
  29.                             'password' => md5($new_password)
  30.                         );
  31.                         $model_user->updatePassword($user_id, $data);
  32.                         $r = 0;
  33.                     } else {
  34.                         $r = 1;
  35.                         $msg = "Password does not match. Please try again.";
  36.                     }
  37.                 } else {
  38.                     $r = 2;
  39.                     $msg = 'Password must contain at least 6 characters. Please try again.';
  40.                 }
  41.             } else {
  42.                 $r = 3;
  43.                 $msg = "Your current password is incorrect. Please try again.";
  44.             }
  45.             if($this->_isAjaxRequest()){
  46.                 $this->setNoRender();
  47.                 $res = array(
  48.                     'r' => $r,
  49.                     'msg'=>$msg,
  50.                 );
  51.                 echo json_encode($res);
  52.             }
  53.         }
  54.     }
  55.    
  56.     public function indexAction() {
  57.         $model_user = new Model_Azuser();
  58.         $oneUser = $_SESSION['user'];
  59.         $currentTeam = $_SESSION['currentTeam'];
  60.         if (!$currentTeam) {
  61.             $this->_redirect(BASE_URL . 'team/listTeam');
  62.         }
  63.        
  64.         $this->view->config = $currentTeam;
  65.         $myProfile = array(
  66.             "azStackUserID" => $oneUser['id'],
  67.             "userCredentials" => $oneUser['password'],
  68.             "fullname" => $oneUser['fullname'],
  69.             "avatar" => $oneUser['avatar90'] ? (EMMA_STATIC_URL . $oneUser['avatar90']) : '',
  70.             "userId" => null,
  71.             "status" => 1,
  72.             "currentTime" => time()
  73.         );
  74.         $this->view->myProfile = json_encode($myProfile);
  75.     }
  76.  
  77.     /**
  78.      * Logout
  79.      */
  80.     public function signoutAction() {
  81.         setcookie('user', "", time() - (60 * 60 * 24 * 7), "/");
  82.         unset($_SESSION['user']);
  83.         unset($_SESSION['currentTeam']);
  84.         $this->_redirect(BASE_URL . 'signin');
  85.     }
  86.  
  87. }
Add Comment
Please, Sign In to add comment