public function postLogin()
 {
     $token = '1kcna4n93-mc29023hfhfb3497cb3287s';
     $username = \Input::get('username');
     $password = \Input::get('password');
     if (\Auth::validate(['username' => $username, 'password' => $password])) {
         $user = \App\User::where('username', $username)->first();
         if ($user) {
             $userArray = $user->toArray();
             $userArray['api_key'] = $token;
             return $userArray;
         } else {
             return response()->json(['error' => 'Incorrect credentials']);
         }
     }
 }
Пример #2
0
 public function login()
 {
     // Getting all post data
     $data = Input::all();
     // Applying validation rules.
     $rules = array('email' => 'required|email', 'password' => 'required|min:6');
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         // If validation falis redirect back to login.
         return Redirect::to('admin/login')->withInput(Input::except('password'))->withErrors($validator);
     } else {
         $userdata = array('email' => Input::get('email'), 'password' => Input::get('password'));
         // doing login.
         if (Auth::validate($userdata)) {
             if (Auth::attempt($userdata)) {
                 return Redirect::intended('/categories');
             }
         } else {
             // if any error send back with message.
             Session::flash('error', 'Something went wrong');
             return Redirect::to('admin/login');
         }
     }
 }