コード例 #1
0
ファイル: LoginController.php プロジェクト: taekunger/kodekit
 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);
     }
 }
コード例 #2
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();
 }
コード例 #3
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();
 }
コード例 #4
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();
     }
 }
コード例 #5
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();
     }
 }
コード例 #6
0
ファイル: Response.php プロジェクト: taekunger/kodekit
 /**
  * redirect to <pre>$location</pre> or any Error page
  * @param  string|Code $location url to move to 
  * @param  array $with params sent with the url
  * @param  int $after num of second to wait before redirecting
  * @return void
  */
 public static function redirectTo($location, $with = [], $after = 0)
 {
     if (!empty($with)) {
         foreach ($with as $k => $v) {
             Request::appendParam($k, $v);
         }
     }
     if (empty($location)) {
         $location = Url::app();
     } else {
         if (!empty($location) && $after > 0) {
             // Redriect with a after:
             header("Refresh: {$after}; url={$location}");
             return;
         }
     }
     header("Location: {$location}");
 }
コード例 #7
0
ファイル: UserController.php プロジェクト: taekunger/kodekit
 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);
     }
 }
コード例 #8
0
ファイル: Router.php プロジェクト: taekunger/kodekit
 public function run()
 {
     try {
         if (isset($_SERVER['REQUEST_METHOD'])) {
             $request_method = $_SERVER['REQUEST_METHOD'];
             $request_method = Request::isAjax() ? 'AJAX' : $request_method;
             $inputFlag = Request::hasParam('_token');
             // check the request method if PUT, DELETE or POST
             if ($request_method == 'POST') {
                 if (isset($_POST['_method'])) {
                     $request_method = $_POST['_method'];
                 }
             }
             // check if the request method not supported
             if (!in_array($request_method, ['POST', 'GET', 'PUT', 'AJAX', 'DELETE'])) {
                 throw new BadRequestException('Unauthorized: Access is denied, REQUEST_METHOD not found');
             }
             $res = null;
             // if any routes are set with the request method
             if (isset($this->routes[$request_method])) {
                 foreach ($this->routes[$request_method] as $route) {
                     // find the route that matches the requested url
                     if ($route->equals($this->url)) {
                         // if the token field is set check the token
                         if ($route->token) {
                             $tokenFlag = Token::match(Request::getParam('_token'));
                             if (!$inputFlag || $inputFlag && !$tokenFlag) {
                                 throw new TokenMissMatchException('Unauthorized: Access is denied, Token Miss Match!');
                                 die('Token missmatch!');
                             }
                         }
                         // executes the requested route
                         $res = $route->exec();
                         if (is_string($res)) {
                             echo $res;
                         } else {
                             if (!is_null($res)) {
                                 dd($res);
                             }
                         }
                         return;
                     }
                 }
             }
             Response::error(404);
         } else {
             throw new BadRequestException('Unauthorized: Access is denied, REQUEST_METHOD not found');
         }
     } catch (Exception $exc) {
         die($exc->getMessage() . ' please go <a href="' . Request::getPrevUrl() . '">back.</a>');
     }
 }