Beispiel #1
0
 public function signup()
 {
     // grappping the registered user information via request
     $name = Request::getParam('name');
     $email = Request::getParam('email');
     $pass = Request::getParam('pass');
     $mobile = Request::getParam('mobile');
     $tel = Request::getParam('tel');
     $address = Request::getParam('address');
     $diagnostic = Request::getParam('diagnostic');
     $description = Request::getParam('description');
     $hash = UserModel::getHash();
     $user_columns = ['name' => $name, 'email' => $email, 'pass' => Hash::make($pass), 'mobile' => $mobile, 'tel' => $tel, 'address' => $address, 'hash' => $hash, 'avatar' => ''];
     // inserting new user
     if (UserModel::insert($user_columns)) {
         // check if there is a complain then insert it
         $complain = ['user_id' => UserModel::lastId(), 'diagnostic' => $diagnostic, 'description' => $description];
         if (!empty($description) && !empty($diagnostic)) {
             ComplainModel::insert($complain);
         }
         // inserting permissions for the user as normal
         $permissions = ['user_id' => UserModel::lastId()];
         PermissionModel::insert($permissions);
         // login the user
         $u = new User($hash);
         $u->login();
         // redirect the user to profile page
         redirect(route('user.profile'));
     } else {
         Response::error(401);
     }
 }
 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();
 }
Beispiel #3
0
 public static function getHash()
 {
     $hash = Hash::unique(30);
     while (self::findBy(['hash' => $hash])) {
         $hash = Hash::unique(30);
     }
     return $hash;
 }
Beispiel #4
0
 private function getRememberMe()
 {
     $remember_me = Hash::unique(30);
     while (self::findBy(['remember_me' => $remember_me])) {
         $remember_me = Hash::unique(30);
     }
     return $remember_me;
 }
Beispiel #5
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);
     }
 }