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(); } }
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(); }
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(); } }
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(); } }
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(); } }
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(); } }
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); } }
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(); }