コード例 #1
0
ファイル: UserController.php プロジェクト: taekunger/kodekit
 public function profile()
 {
     $user = User::getData();
     if (!empty($user)) {
         // setting a new properity for the user permission
         $permission = PermissionModel::first('user_id = ?', [$user->id]);
         $user->permission = $permission->permission;
         // if the user is admin then will fetch the not replied complains
         $requests = null;
         if ($permission->permission == 'admin') {
             $requests = ComplainModel::with(['status' => 'bending']);
             if (count($requests)) {
                 foreach ($requests as $request) {
                     // fetching the data for the patient who made the complain
                     $request->patient = UserModel::id($request->user_id);
                 }
             }
             $requests_count = count($requests);
             return twig('profile-admin.html', ['user' => $user, 'requests' => $requests, 'requests_count' => $requests_count]);
         }
         $msgs = $complains = null;
         if ($permission->permission == 'normal') {
             // fetching the current user messages
             $msgs = MessageModel::with(['user_id' => $user->id]);
             // fetching the current user complains
             $complains = ComplainModel::with(['user_id' => $user->id]);
             $msgs_count = count(MessageModel::with(['user_id' => $user->id, 'viewed' => 0]));
             return twig('profile-user.html', ['user' => $user, 'complains' => $complains, 'msgs' => $msgs, 'msgs_count' => $msgs_count]);
         }
     } else {
         Session::flash("msg", '<li><span class="msg-warning">Warning: </span> Humm!... you want to cheat, access denied</li>');
         goBack();
     }
 }
コード例 #2
0
ファイル: LoginController.php プロジェクト: taekunger/kodekit
 public function signin()
 {
     $email = Request::getParam('email');
     $pass = Request::getParam('pass');
     $remember = !empty(Request::getParam('remember'));
     $admin = !empty(Request::getParam('admin'));
     $user = UserModel::first('email = ?', [$email]);
     if ($user && Hash::match($pass, $user->pass)) {
         $permission = PermissionModel::first('user_id = ?', [$user->id])->permission;
         // check permision type for the user
         if ($admin && $permission != 'admin') {
             Session::flash("msg", '<li><span class="msg-error">Error: </span> Ooops!... No admin found (wrong email or password ) , let\'s try one more time!</li>');
             Session::flash("data", Request::getALlParams());
             goBack();
             exit;
         } else {
             if (!$admin && $permission == 'admin') {
                 Session::flash("msg", '<li><span class="msg-error">Error: </span> Ooops!... No User found (wrong email or password ) , let\'s try one more time!</li>');
                 Session::flash("data", Request::getALlParams());
                 goBack();
                 exit;
             }
         }
         $u = new User($user->hash);
         $u->login($remember);
         redirect(route('user.profile'));
     } else {
         Session::flash("msg", '<li><span class="msg-warning">Warning: </span> Ooops!... wrong email or password, let\'s try one more time!</li>');
         Session::flash("data", Request::getALlParams());
         goBack();
     }
 }
コード例 #3
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();
 }
コード例 #4
0
ファイル: UserMiddleware.php プロジェクト: taekunger/kodekit
 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();
     }
 }
コード例 #5
0
ファイル: LoginMiddleware.php プロジェクト: taekunger/kodekit
 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();
     }
 }
コード例 #6
0
 function control($next)
 {
     $user_data = Request::getALlParams();
     Validation::check($user_data, ['name' => ['required' => true, 'unicode_space' => true, 'min' => 2, 'title' => 'Name'], 'email' => ['required' => true, 'field' => 'email', 'unique' => 'users', 'title' => 'E-mail'], 'pass' => ['required' => true, 'field' => 'nr_password', 'min' => 8, 'title' => 'Password'], 'tel' => ['required' => true, 'field' => 'phone', 'unique' => 'users', 'title' => 'Telephone'], 'mobile' => ['required' => true, 'field' => 'phone', 'unique' => 'users', 'title' => 'Mobile'], 'repass' => ['required' => true, 'matches' => 'pass', 'title' => 'Re-password']]);
     if (Validation::passed()) {
         return $next();
     } else {
         $msgs = Validation::getAllErrorMsgs();
         $str = '';
         foreach ($msgs as $msg) {
             $str .= '<li><span class="msg-error" >Error: </span> ' . $msg . '</li>';
         }
         Session::flash('msg', $str);
         Session::flash('data', $user_data);
         goBack();
     }
 }
コード例 #7
0
 function control($next)
 {
     $complain = Request::getALlParams();
     Validation::check($complain, ['description' => ['required' => true, 'title' => 'Complain']]);
     if (Validation::passed()) {
         return $next();
     } else {
         $msgs = Validation::getAllErrorMsgs();
         $str = '';
         foreach ($msgs as $msg) {
             $str .= '<li><span class="msg-error" >Error: </span> ' . $msg . '</li>';
         }
         Session::flash('msg', $str);
         Session::flash('data', $complain);
         goBack();
     }
 }
コード例 #8
0
ファイル: User.php プロジェクト: taekunger/kodekit
 public static function getHash()
 {
     return Session::get(Config::extra('session.remember_me'));
 }
コード例 #9
0
ファイル: AdminController.php プロジェクト: taekunger/kodekit
 public function reply()
 {
     $marks = Request::getParam('marks');
     $reply = Request::getParam('reply');
     $report = Request::getFile('report');
     $status = '';
     // if the complains selected and the replies sent
     if (count($marks) && !empty($reply)) {
         // loop through each complain and reply to
         foreach ($marks as $mark) {
             //confirm that the complain id is exist
             if (!empty($complain = ComplainModel::id($mark))) {
                 $report_f = true;
                 // if the report uploaded
                 if ($report) {
                     $tmp = $report->tmp_name;
                     $file_parts = explode('.', $report->name);
                     //export the extension of the file
                     $report_ext = end($file_parts);
                     //remove the extension
                     array_pop($file_parts);
                     //get the file name
                     $report_name = implode('_', $file_parts);
                     // get the new file path
                     $report = "resources/reports/{$report->name}";
                     // create unique name for the file
                     while (file_exists(path($report))) {
                         $report = $report_name . '_' . rand(0, 9999) . ".{$report_ext}";
                         $report = "resources/reports/{$report}";
                     }
                     $report_f = move_uploaded_file($tmp, path($report));
                 }
                 //building new message for reply
                 $msg = ['complain_id' => $complain->id, 'user_id' => $complain->user_id, 'title' => "<b>[Reply to:] </b> {$complain->diagnostic} <b>[Num:] </b> {$complain->id} <b>[Date:] </b> {$complain->created_at}.", 'body' => $reply, 'report' => $report];
                 // insert the message and update the complain status to replied
                 if ($report_f && MessageModel::insert($msg) && ComplainModel::update(['status' => 'replied'], 'id = ?', [$complain->id])) {
                     $status .= '<li><span class="msg-success">Success: </span> Replied to Complain #' . $complain->id . ' Successfully</li>';
                 } else {
                     $status .= '<li><span class="msg-error">Error: </span> Reply to Complain #' . $complain->id . ' Failed</li>';
                 }
             }
         }
         //if no complain selected or empty reply
     } else {
         $status .= '<li><span class="msg-error">Error: </span> Mark at least one complain to be replied and couldn\'t reply with empty</li>';
     }
     Session::flash("msg", $status);
     goBack();
 }