def mutate(self, info, otp, **kwargs): Validation.check_is_empty(otp, 'OTP') user = info.context.user Validation.check_user_login(user) profile = UserProfile.objects.get(user=user) if profile.mobile_otp != otp: raise GraphQLError("Incorrect OTP, Please try again!") profile.mobile_otp = None profile.phone_verified = True profile.save() return VerifyMobileOTP(status='success', message='Mobile successfully verified!')
def mutate(self, info, otp, email, **kwargs): Validation.check_is_empty(email, 'Email') Validation.check_is_empty(otp, 'OTP') user = User.objects.get(email=email) if not user: raise GraphQLError("Email not registered") profile = UserProfile.objects.get(user=user) if profile.otp != otp: raise GraphQLError("Incorrect OTP, Please try again!") profile.otp = None profile.save() return VerifyOTP(status='success', message='OTP successfully verified!')
def mutate(self, info, oldpassword, newpassword, **kwargs): user = info.context.user Validation.check_user_login(user) Validation.check_is_empty(oldpassword, 'Old Password') Validation.check_is_empty(newpassword, 'New Password') user_auth = authenticate(username=user.email, password=oldpassword) if user_auth is None: raise GraphQLError("Incorrect Old Password") user.set_password(newpassword) user.save() return ChangePassword(message='Password Changed!', status='success')
def mutate(self, info, email, newpassword, **kwargs): Validation.check_is_empty(email, 'Email') Validation.check_is_empty(newpassword, 'New Password') user = User.objects.get(email=email) if not user: raise GraphQLError("Email not registered") profile = UserProfile.objects.get(user=user) if profile.otp != None: raise GraphQLError("Please verify OTP!") user.set_password(newpassword) user.save() return ResetPassword(status='success', message='Password successfully updated!')
def mutate(self, info, name, email, phone, password, **kwargs): Validation.check_is_empty(name, 'Name') Validation.check_is_empty(password, 'Password') name_slice = name.split(" ") first_name = name_slice[0].title() last_name = ' '.join(name_slice[1:]) if len(name_slice) > 1 else '' device_id = kwargs.get('device_id', "") device_token = kwargs.get('device_token', "") device_type = kwargs.get('device_type', "") device_os = kwargs.get('device_os', "") device_version = kwargs.get('device_version', "") profile = UserProfile.objects.filter(primary_phone=phone).first() if profile: raise GraphQLError("Mobile already registered, Please Login!") device = UserDevice.objects.filter(device_id=device_id).first() if device: raise GraphQLError("Device already registered, Please Login!") try: user = User(first_name=first_name, last_name=last_name, email=email) user.set_password(password) user.save() except: raise GraphQLError("Email already registered, Please Login!") if device_id and device_type: UserDevice.objects.create(user=user, device_id=device_id, device_token=device_token, device_type=device_type, device_os=device_os, device_version=device_version) UserProfile.objects.create(user=user, primary_phone=phone) return Register(user=user)
def mutate(self, info, email, **kwargs): Validation.check_is_empty(email, 'Email') user = User.objects.filter(email=email).first() if not user: raise GraphQLError("Email not registered") try: token = random_token(6) profile = UserProfile.objects.get(user=user) profile.otp = token profile.save() _thread.start_new_thread( sendmail, ('forgot_password', email, token, user.first_name)) status = 'success' message = 'OTP successfully sent!' except Exception as e: message = e status = 'error' return ForgotPassword(status=status, message=message)