예제 #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)
 {
     if (PermissionModel::findBy(['user_id' => User::getData()->id, 'permission' => 'admin'])) {
         return $next();
     } else {
         goBack();
     }
 }
예제 #3
0
 public function update()
 {
     $user = User::getData();
     $name = Request::getParam('name');
     $email = Request::getParam('email');
     $newpass = Request::getParam('newpass');
     $tel = Request::getParam('tel');
     $address = Request::getParam('address');
     $mobile = Request::getParam('mobile');
     $gender = Request::getParam('gender');
     $avatar = '';
     if (Request::hasFile('avatar')) {
         $avatar = 'images/' . Request::getFile('avatar')->name;
     }
     if (empty($newpass)) {
         $newpass = Request::getParam('pass');
     }
     if (empty($avatar)) {
         $avatar = $user->avatar;
     }
     if (empty($address)) {
         $address = $user->address;
     }
     $user_columns = ['name' => $name, 'email' => $email, 'pass' => Hash::make($newpass), 'mobile' => $mobile, 'tel' => $tel, 'gender' => $gender, 'address' => $address, 'avatar' => $avatar, 'updated_at' => Carbon::now()];
     if (UserModel::update($user_columns, "id = ?", [User::getData()->id])) {
         goBack();
     } else {
         Response::error(401);
     }
 }
예제 #4
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]);
 }