protected function userID($request) { if ($request->header('x-auth-login') != null) { $next = $request->header('x-auth-login'); } else { $next = $request->input('x-auth-login'); } $token = Token::where('token', $next)->value('user_id'); return $token; }
public function logout(Request $request) { if (!empty($request->input('x-auth-login'))) { $remember_token = $request->input('x-auth-login'); } else { $remember_token = $request->header('x-auth-login'); } Token::where('token', $remember_token)->update(['token' => null]); return $this->httpOk(); }
public function handle($request, Closure $next) { //login authentication if (!empty($request->input('x-auth-login'))) { $x_login = $request->input('x-auth-login'); } else { $x_login = $request->header('x-auth-login'); } $cek_token = Token::where('token', $x_login)->first(); if (!$x_login) { $response['error'][] = ['status' => false, 'message' => "An access token is required to request this resource.", 'required' => "x-auth-login", 'code' => 402]; return response()->json($response, 402); } if (is_null($cek_token)) { $response['error'][] = ['status' => false, 'message' => "This token login unauthorized", 'code' => 401]; return response()->json($response, 401); } //table key authentication /* if (!empty($request->input('x-auth-key'))) { $x_key = $request->input('x-auth-key'); } else{ $x_key = $request->header('x-auth-key'); } $cek_token = User::where('key_id', $x_key)->first(); if (!$x_key) { $response['error'][] = [ 'status' => false, 'message' => "An access token is required to request this resource.", 'required' => "x-auth-key", 'code' => 402 ]; return response()->json($response, 402); } if (is_null($cek_token)) { $response['error'][] = [ 'status' => false, 'message' => "This token app key unauthorized", 'code' => 401 ]; return response()->json($response, 401); }*/ //cek this table key and token user login /* $combine = User::where('remember_token', $x_login)->first(); if (!$combine) { $response['error'][] = [ 'status' => false, 'message' => "Cannot access this app.", 'required' => "x-auth-key and x-auth-login not math", 'code' => 422 ]; return response()->json($response, 422); }*/ return $next($request); }
public function registerFranchisor(Request $request) { $validator = Validator::make($request->all(), ['email' => 'required|email|unique:users', 'password' => 'required|min:6']); if ($validator->fails()) { $message = $validator->errors(); return $this->httpUnprocessableEntity($message); } $salt = hash('sha256', $request->input('email') . $request->input('password') . time() . mt_rand()); $new_key = substr($salt, 0, 10); $password = md5($request->input('password')); $email = $request->input('email'); $salt = hash('sha256', $email . $password . time() . mt_rand()); $token = substr($salt, 0, 40); if ($this->konfigurasi($new_key)) { $user = new User(); $user->email = $email; $user->password = $password; $user->key_id = $new_key; $user->level = 'franchisor'; if ($user->save()) { $user_id = User::where('email', $email)->first(); $franchisor = new Franchisor(); $franchisor->id = $user_id->id; $franchisor->save(); $tokens = new Token(); $tokens->user_id = $user_id->id; $tokens->token = $token; $tokens->save(); /* $data = array( 'name' => 'Pos Mikro', ); Mail::send('emails.test', $data, function ($message) { $message ->to('*****@*****.**', 'Tofa Riyadi') ->subject('Registration'); });*/ $response = ['email' => $email, 'token' => $token, 'level' => $user_id->level]; return $this->httpCreate($response); } } return $this->httpServerError(); }