Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function changePassword(Request $request)
- {
- try{
- $validator = Validator::make($request->all(), [
- 'current_pwd' => 'required',
- 'new_pwd'=>'required'
- ]);
- if ($validator->fails()) {
- $error_message=implode(",",$validator->messages()->all());
- throw new Exception($error_message,Config('constants.status_code.fail'));
- }
- $user = User::find(auth()->user()->id);
- if($user)
- {
- if(Hash::check($request->get('current_pwd'),$user->password))
- {
- if(Hash::check($request->get('new_pwd'),$user->password))
- {
- throw new Exception("Your new password cannot be same as old password", Config('constants.status_code.fail'));
- }
- $user->password = Hash::make($request->get('new_pwd'));
- $user->save();
- return response()->json([
- 'settings' => [
- 'status' => 1,
- 'statusCode' => Config('constants.status_code.success'),
- 'message' => trans('Your Password has been updated successfully')
- ],
- 'data' => array()
- ],Config('constants.status_code.success'));
- }
- else
- {
- throw new Exception("Invalid current password", Config('constants.status_code.fail'));
- }
- }
- else
- {
- throw new Exception("Unauthorized", Config('constants.status_code.fail'));
- }
- }
- catch(Exception $e)
- {
- return response()->json([
- 'settings' => [
- 'status' => 0,
- 'statusCode' => $e->getCode(),
- 'message' => $e->getMessage()
- ],
- 'data' => [
- ]
- ],$e->getCode());
- }
- }
Add Comment
Please, Sign In to add comment