auth = $auth; } /** * Login user and return correct response. * * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response */ public function login() { $username = Input::get('username'); $password = Input::get('password'); if($this->auth->attempt(['username' => $username, 'password' => $password], true)) { return response('Success', 200); } return response('Unauthorized', 401); } /** * Return user data for frontend. Currently only username is needed. * * @return array */ public function userData() { return [ 'username' => Auth::user()->username ]; } /** * @param $type * * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response */ public function changeUser($type) { $value = $type == 'username' ? Input::get('username') : bcrypt(Input::get('password')); $user = Auth::user(); $user->{$type} = $value; if($user->save()) { return response('Success', 200); } return response('Server Error', 500); } /** * Logout user and redirect to home. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function logout() { $this->auth->logout(); return redirect('/'); } }