/** * @author: lmkhang (skype) * @date: 2016-01-15 * Action: Admin login */ public function login(Request $request) { //check islogged if ($this->isLoggedAdmin()) { //set Flash Message $this->setFlash('message', 'Logged!'); return Redirect::intended('/adminntw')->with('message', 'Logged!'); } $post = $request->all(); $info = $this->trim_all($post['login']); //Setup validation $validator = Validator::make($info, ['account' => 'required|min:5|max:100', 'password' => 'required|min:5|max:50']); //Checking if ($validator->fails()) { // The given data did not pass validation //set Flash Message $this->setFlash('message', 'Errors!'); return redirect()->back(); } $salt = \App\Config::where(['prefix' => 'admin', 'name' => 'salt', 'del_flg' => 1])->get()[0]['value']; $pwd = $this->encryptString($info['password'], $salt); $admin_get = new \App\Admin(); $admin = $admin_get->checkAccount($info['account'], $pwd); //set Session if (!$admin) { //set Flash Message $this->setFlash('message', 'This account is not available!'); return redirect()->back()->with('message', 'This account is not available!'); } //set Session $this->setLogSession($admin->toArray()); //set Flash Message $this->setFlash('message', 'Login successfully!'); return Redirect::intended('/adminntw')->with('message', 'Login successfully!'); }
/** * @author: lmkhang - skype * @date: 2016-01-04 * Checking existed account */ protected function checkAccount($info) { //Check isLogged if ($this->isLoggedAdmin()) { die; } //Message $result = null; //Check Username if (isset($info['account']) && $info['account'] && isset($info['password']) && $info['password']) { $salt = \App\Config::where(['prefix' => 'admin', 'name' => 'salt', 'del_flg' => 1])->get()[0]['value']; $password = $this->encryptString($info['password'], $salt); $admin = new \App\Admin(); $result = $admin->checkAccount($info['account'], $password); } return $result; }
/** * @author: lmkhang - skype * @date: 2016-01-10 * Checking admin login */ public function admin_login(Request $request) { if ($this->isLoggedAdmin()) { die; } $message = 'This account is not available'; if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $post = $request->all(); $info = $this->trim_all($post['login']); $salt = \App\Config::where(['prefix' => 'admin', 'name' => 'salt', 'del_flg' => 1])->get()[0]['value']; $pwd = $this->encryptString($info['password'], $salt); $admin_get = new \App\Admin(); $admin = $admin_get->checkAccount($info['account'], $pwd); //set Session if ($admin) { $message = ''; } header('Content-Type: application/json'); echo json_encode(['message' => $message]); exit; } }