Пример #1
0
 function control($next)
 {
     $user_data = Request::getALlParams();
     Validation::check($user_data, ['name' => ['required' => true, 'unicode_space' => true, 'min' => 2, 'title' => 'Name'], 'email' => ['field' => 'email', 'title' => 'E-mail'], 'pass' => ['required' => true, 'field' => 'nr_password', 'min' => 8, 'title' => 'Password'], 'newpass' => ['field' => 'nr_password', 'min' => 8, 'title' => 'New Password'], 'repass' => ['matches' => 'newpass', 'title' => 'Re-password'], 'tel' => ['field' => 'phone', 'title' => 'Telephone'], 'mobile' => ['field' => 'phone', 'title' => 'Mobile']]);
     $avatar = Request::getFile('avatar');
     $str = '';
     if (Validation::passed()) {
         // grapping the current user data
         $user = User::getData();
         // password check
         if (Hash::match(Request::getParam('pass'), $user->pass)) {
             // if the avatar is set it will be tested
             $avatarFlag = true;
             if (!empty($avatar)) {
                 $avatarFlag = $avatar->size <= 100000 && scanImageToPng($avatar->tmp_name, Url::resource("images/{$avatar->name}"));
                 if (!$avatarFlag) {
                     $str .= '<li><span class="msg-error" >Error: </span> The Avatar must be an image and less that 10 MB</li>';
                 }
             }
             //if the email changed it will be tested
             $email = Request::getParam('email');
             $emailFlag = true;
             if ($user->email != $email && UserModel::findBy(['email' => $email])) {
                 $emailFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Email already Exists choose another one</li>';
             }
             //if the telephone changed it will be tested
             $tel = Request::getParam('tel');
             $telFlag = true;
             if ($user->tel != $tel && UserModel::findBy(['tel' => $tel])) {
                 $telFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Telephone already Exists choose another one</li>';
             }
             //if the mobile changed it will be tested
             $mobile = Request::getParam('mobile');
             $mobileFlag = true;
             if ($user->mobile != $mobile && UserModel::findBy(['mobile' => $mobile])) {
                 $mobileFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Mobile already Exists choose another one</li>';
             }
             // if the avatar test and the email test and the mobile test and the telephone test are passed,
             //  move to next step
             if ($avatarFlag && $emailFlag && $mobileFlag && $telFlag) {
                 return $next();
             }
         } else {
             $str .= '<li><span class="msg-error" >Error: </span> The Password doesn\'t match the current one</li>';
         }
     }
     $msgs = Validation::getAllErrorMsgs();
     if (count($msgs)) {
         foreach ($msgs as $msg) {
             $str .= '<li><span class="msg-error" >Error: </span> ' . $msg . '</li>';
         }
     }
     Session::flash('msg', $str);
     Session::flash('data', $user_data);
     goBack();
 }
Пример #2
0
 public function control($next)
 {
     $u = new User();
     if ($u->isLoggedIn()) {
         return $next();
     } else {
         Session::flash("msg", '<li><span class="msg-warning">Warning: </span> Humm!... you want to cheat, please <a href="' . Url::route('login') . '">login</a> first and go back later!</li>');
         goBack();
     }
 }
Пример #3
0
 public function control($next)
 {
     $u = new User();
     if ($u->isLoggedIn()) {
         Session::flash("msg", '<li><span class="msg-warning">Warning: </span> You cannot login twice, please <a href="' . Url::route('logout') . '">Logout</a> first and try again!</li>');
         goBack();
     } else {
         return $next();
     }
 }
Пример #4
0
 public function delete()
 {
     $user = User::getData();
     if (!empty($user->avatar)) {
         @unlink(Url::resource($user->avatar));
     }
     $userFlag = UserModel::delete('id = ?', [$user->id]);
     $perFlag = PermissionModel::delete('user_id = ?', [$user->id]);
     $msgFlag = MessageModel::delete('user_id = ?', [$user->id]);
     $compFlag = ComplainModel::delete('user_id = ?', [$user->id]);
     $status = $userFlag && $perFlag && $msgFlag && $compFlag;
     if ($status) {
         $u = new User();
         $u->logout();
     }
     Response::json(['status' => $status]);
 }
Пример #5
0
function route($path, $args = [])
{
    return Url::route($path, $args);
}
Пример #6
0
 /**
  * redirect back or to home page if the previous url not found
  * @param  array $with params sent with the url
  * @param  int $after num of second to wait before redirecting
  * @return void
  */
 public static function redirectBack($with = [], $after = 0)
 {
     if (isset($_SERVER['HTTP_REFERER'])) {
         self::redirectTo($_SERVER['HTTP_REFERER'], $with, $after);
     } else {
         self::redirectTo(Url::app(), $with, $after);
     }
 }
Пример #7
0
 /**
  * Returns the complete URL of the current page (not reliable because not all getClient-agents
  * @return (type) (description)
  */
 public static function getPrevUrl()
 {
     return self::SERVER('HTTP_REFERER') ? self::SERVER('HTTP_REFERER') : Url::app();
 }
Пример #8
0
 public function delete($id)
 {
     $current = User::getData();
     $admin = PermissionModel::findBy(['user_id' => $current->id, 'permission' => 'admin']);
     $userFlag = $perFlag = $msgFlag = $compFlag = FALSE;
     if ($current->id != $id && $admin) {
         $avatar = UserModel::id($id)->avatar;
         if (!empty($avatar)) {
             @unlink(Url::resource($avatar));
         }
         $userFlag = UserModel::delete('id = ?', [$id]);
         $perFlag = PermissionModel::delete('user_id = ?', [$id]);
         $msgFlag = MessageModel::delete('user_id = ?', [$id]);
         $compFlag = ComplainModel::delete('user_id = ?', [$id]);
     }
     Response::json(['status' => $userFlag && $perFlag && $msgFlag && $compFlag]);
 }