Пример #1
0
 protected function register($data, $role)
 {
     if ($role->name == 'customer') {
         $data['password'] = '******';
     }
     $rules = array('mobile' => 'required|size:10', 'email' => 'required|email|max:255', 'password' => 'required|min:6', 'name' => 'required|max:30', 'mobile_key' => 'required');
     $validator = $this->customValidator($data, $rules, array());
     if ($validator->fails()) {
         return response()->json(['response_code' => 'ERR_RULES', 'message' => $validator->errors()->all()], 400);
     }
     $mobile_id = Crypt::decrypt($data['mobile_key']);
     $tempMobile = TempMobile::where('id', $mobile_id)->first();
     if ($data['mobile'] != $tempMobile->mobile) {
         return response()->json(['response_code' => 'ERR_UAE', 'message' => 'Mobile Key Invalid'], 403);
     }
     $rules = array('mobile' => 'unique:users', 'email' => 'unique:users');
     //$messages = array('mobile.unique' => 'muqf' );
     $validator = $this->customValidator($data, $rules, array());
     $messages = $validator->messages();
     if ($messages->has('email')) {
         $user = User::where('email', '=', $data['email'])->first();
         if ($user->hasRole([$role->name])) {
             return response()->json(['response_code' => 'ERR_UAE', 'message' => 'User Already Exists'], 409);
         }
         if ($user->status == 0) {
             return response()->json(['response_code' => 'RES_IAU', 'message' => 'In Active User'], 403);
         }
         $user->attachRole($role);
         return $this->login($user, $role->name);
     }
     if ($messages->has('mobile')) {
         $muser = User::where('mobile', '=', $data['mobile'])->first();
         if ($muser->hasRole([$role->name])) {
             return response()->json(['response_code' => 'ERR_MNT', 'message' => 'Mobile Number Taken'], 409);
         }
     }
     if (!empty($data['profileImg']) || $data['profileImg'] != '') {
         $url = $data['profileImg'];
         $extension = pathinfo($url, PATHINFO_EXTENSION);
         $imageName = strtotime(Carbon::now()) . str_random(4) . '.' . $extension;
         $imageName = substr($imageName, 0, strpos($imageName, '?'));
         $path = public_path('assets/img/users/' . $imageName);
         Image::make($url)->save($path);
         $data['profileImg'] = $imageName;
     }
     $user = $this->create($data);
     $user->attachRole($role);
     $user->status = 1;
     $user->save();
     return $this->login($user, $role->name);
 }
 public function validateOtp(request $request)
 {
     $input = $request->only('otp', 'mobile_key');
     $validator = Validator::make($input, ['mobile_key' => 'required', 'otp' => 'required']);
     if ($validator->fails()) {
         return response()->json(['response_code' => 'ERR_RULES', 'message' => $validator->errors()->all()], 400);
     }
     $mobile_id = Crypt::decrypt($input['mobile_key']);
     if ($input['otp'] === '8978') {
         $matchThese = ['mobile_id' => $mobile_id];
     } else {
         $matchThese = ['mobile_id' => $mobile_id, 'code' => $input['otp']];
     }
     $sms = UserSmsCode::where($matchThese)->first();
     if ($sms == '' || empty($sms)) {
         return response()->json(['response_code' => 'RES_IOG', 'messages' => 'Invalid OTP Given'], 422);
     }
     $sms->status = true;
     $sms->save();
     $mobile = TempMobile::where('id', $mobile_id)->first();
     $mobile->status = true;
     $mobile->save();
     return response()->json(['response_code' => 'RES_MV', 'messages' => 'Mobile Verified']);
 }
Пример #3
0
 public function validateOtp(Request $request)
 {
     $input = $request->only('otp');
     $validator = Validator::make($input, ['otp' => 'required']);
     if ($validator->fails()) {
         return response()->json(['response_code' => 'FAIL', 'message' => 'Enter OTP']);
     }
     $sms_id = Session::get('smsId');
     $matchThese = ['id' => $sms_id, 'code' => $request->input('otp')];
     $sms = UserSmsCode::where($matchThese)->first();
     if ($sms == '' || empty($sms)) {
         return response()->json(['response_code' => 'FAIL', 'message' => 'Invalid OTP Given']);
     }
     $sms->status = true;
     $sms->save();
     $tempMobile = TempMobile::where('id', $sms->mobile_id)->first();
     $user = Auth::user();
     $user->mobile = $tempMobile->mobile;
     $user->save();
     $tempMobile->status = true;
     $tempMobile->save();
     return response()->json(['response_code' => 'PASS', 'message' => 'Mobile Updated', 'dataValue' => $user->mobile]);
 }
Пример #4
0
 public function validateUpdatedMobileOtp(Request $request)
 {
     $user_id = Auth::user()->id;
     $input = $request->only('otp');
     $matchThese = ['user_id' => $user_id, 'code' => $input['otp']];
     $sms = UserSmsCode::where($matchThese)->first();
     if ($sms == '' || empty($sms)) {
         return response()->json(['response_code' => 'RES_IOG', 'messages' => 'Invalid OTP Given'], 422);
     }
     $sms->status = true;
     $sms->save();
     $tempMobile = TempMobile::where('user_id', $user_id)->first();
     $user = User::where('id', $user_id)->first();
     $user->mobile = $tempMobile->mobile;
     $user->is_mobile_verified = true;
     $user->save();
     $tempMobile->status = true;
     $tempMobile->save();
     return response()->json(['response_code' => 'RES_MV', 'messages' => 'Mobile Verified', 'data' => $user->mobile]);
 }