def mutate(self, info, user_type, name, is_employed, occupation, **kwargs): user = info.context.user user_type = user_type.title() Validation.check_user_login(user) Validation.validate_usertype(user_type) try: family = UserFamily.objects.filter(user=user, user_type=user_type).first() if family: family.name = name family.is_employed = is_employed family.occupation = occupation family.save() else: UserFamily.objects.create(user=user, user_type=user_type, name=name, is_employed=is_employed, occupation=occupation) status = 'success' message = 'Family details updated!' instance = UserProfile.objects.filter(user=user).first() instance.completed_family_details = True instance.save() except Exception as e: status = 'error' message = e return UpdateFamily(status=status, message=message)
def resolve_profile(self, info, username=None): user = info.context.user Validation.check_user_login(user) if username: user = User.objects.filter(username=username).first() if not user: raise GraphQLError("User not exist!") profile = UserProfile.objects.filter(user=user).first() return profile
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, 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, **kwargs): user = info.context.user Validation.check_user_login(user) try: token = random_token(6) profile = UserProfile.objects.get(user=user) profile.mobile_otp = token profile.save() status = 'success' message = 'OTP successfully sent!' except Exception as e: message = e status = 'error' return ResendMobileVerification(status=status, message=message, otp=token)
def mutate(self, info, **kwargs): user = info.context.user Validation.check_user_login(user) try: token = random_token(6) profile = UserProfile.objects.get(user=user) profile.email_otp = token profile.save() _thread.start_new_thread( sendmail, ('verify_email', user.email, token, user.first_name)) status = 'success' message = 'OTP successfully sent!' except Exception as e: message = e status = 'error' return ResendEmailVerification(status=status, message=message)
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)
def resolve_get_chat_room(self, info, user1, user2, **kwargs): user = info.context.user Validation.check_user_login(user) user_count = User.objects.filter(username__in=[user1, user2]).count() if user_count != 2 or user1 == user2: raise GraphQLError("User matching Failed, Please contact admin!") room_res = MessageRoom.objects.filter( Q(user1__username=user1, user2__username=user2) | Q(user1__username=user2, user2__username=user1)).first() if room_res: room_id = room_res.id else: room_name = user1 + '|' + user2 user1 = User.objects.get(username=user1) user2 = User.objects.get(username=user2) room = MessageRoom(user1=user1, user2=user2, room_name=room_name) room.save() room_id = room.id return {'room_id': room_id}
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 resolve_hobby(self, info, **kwargs): Validation.check_staff_role(info.context.user) qs = Hobby.objects.all() return qs
def resolve_sub_caste(self, info, **kwargs): Validation.check_staff_role(info.context.user) qs = SubCaste.objects.all() return qs
def resolve_membership(self, info, **kwargs): Validation.check_staff_role(info.context.user) qs = Membership.objects.all() return qs
def resolve_mother_tongue(self, info, **kwargs): Validation.check_staff_role(info.context.user) qs = MotherTongue.objects.all() return qs
def mutate(self, info, **kwargs): user = info.context.user Validation.check_user_login(user) try: instance = UserProfile.objects.filter(user=user).first() if not instance: instance = UserProfile.objects.create(user=user) mother_tongue = kwargs.get('mother_tongue', instance.mother_tongue) if mother_tongue: mother_tongue = Validation.validate_mother_tongue(mother_tongue) religion = kwargs.get('religion', instance.religion) if religion: religion = Validation.validate_religion(religion) caste = kwargs.get('caste', instance.caste) if caste: caste = Validation.validate_caste(caste) raasi = kwargs.get('raasi', instance.raasi) if raasi: raasi = Validation.validate_raasi(raasi) sub_caste = kwargs.get('sub_caste', instance.sub_caste) if sub_caste: sub_caste = Validation.validate_sub_caste(sub_caste) star = kwargs.get('star', instance.star) if star: star = Validation.validate_star(star) highest_education = kwargs.get('highest_education', instance.highest_education) if highest_education: highest_education = Validation.validate_highest_education(highest_education) occupation = kwargs.get('occupation', instance.occupation) if occupation: occupation = Validation.validate_occupation(occupation) instance.gender = kwargs.get('gender', instance.gender) instance.dob = kwargs.get('dob', instance.dob) instance.about_me = kwargs.get('about_me', instance.about_me) instance.about_family = kwargs.get('about_family', instance.about_family) instance.profile_created_by = kwargs.get('profile_created_by', instance.profile_created_by) instance.country = kwargs.get('country', instance.country) instance.city = kwargs.get('city', instance.city) instance.state = kwargs.get('state', instance.state) instance.work_location = kwargs.get('work_location', instance.work_location) instance.native_location = kwargs.get('native_location', instance.native_location) instance.gothram = kwargs.get('gothram', instance.gothram) instance.college = kwargs.get('college', instance.college) instance.height = kwargs.get('height', instance.height) instance.weight = kwargs.get('weight', instance.weight) instance.physical_status = kwargs.get('physical_status', instance.physical_status) instance.body_type = kwargs.get('body_type', instance.body_type) instance.eating_habits = kwargs.get('eating_habits', instance.eating_habits) instance.drinking_habits = kwargs.get('drinking_habits', instance.drinking_habits) instance.smoking_habits = kwargs.get('smoking_habits', instance.smoking_habits) instance.mother_tongue = mother_tongue instance.religion = religion instance.caste = caste instance.raasi = raasi instance.sub_caste = sub_caste instance.star = star instance.highest_education = highest_education instance.employed_in = kwargs.get('employed_in', instance.employed_in) instance.occupation = occupation instance.dosham = kwargs.get('dosham', instance.dosham) if instance.gender and instance.dob and instance.profile_created_by and instance.city: instance.completed_basic_details = True if instance.mother_tongue and instance.height and instance.weight and instance.body_type: instance.completed_profile_details = True if instance.religion and instance.caste and instance.raasi and instance.sub_caste and instance.star: instance.completed_relegious_details = True if instance.highest_education and instance.employed_in and instance.college: instance.completed_professional_details = True instance.save() status='success' message = 'Profile details updated!' except Exception as e: status = 'error' message = e return UpdateProfile(status=status, message=message)
def resolve_notification(self, info, size=100, page=1, **kwargs): Validation.check_user_login(info.context.user) qs = Notification.objects.filter( user=info.context.user).order_by('-updated_ts') return get_wrapper_details(NotificationWrapper, qs, page, size)
def resolve_raasi(self, info, **kwargs): Validation.check_staff_role(info.context.user) qs = Raasi.objects.all() return qs
def resolve_me(self, info): user = info.context.user Validation.check_user_login(user) return user
def resolve_occupation_category(self, info, **kwargs): Validation.check_staff_role(info.context.user) qs = OccupationCategory.objects.all() return qs
def mutate(self, info, **kwargs): user = info.context.user Validation.check_user_login(user) try: instance = PartnerPreference.objects.filter(user=user).first() if not instance: instance = PartnerPreference.objects.create(user=user) mother_tongue = kwargs.get('mother_tongue', instance.mother_tongue) if mother_tongue: mother_tongue = Validation.validate_mother_tongue(mother_tongue) religion = kwargs.get('religion', instance.religion) if religion: religion = Validation.validate_religion(religion) caste = kwargs.get('caste', instance.caste) if caste: caste = Validation.validate_caste(caste) raasi = kwargs.get('raasi', instance.raasi) if raasi: raasi = Validation.validate_raasi(raasi) sub_caste = kwargs.get('sub_caste', instance.sub_caste) if sub_caste: sub_caste = Validation.validate_sub_caste(sub_caste) star = kwargs.get('star', instance.star) if star: star = Validation.validate_star(star) highest_education = kwargs.get('highest_education', instance.highest_education) if highest_education: highest_education = Validation.validate_highest_education(highest_education) occupation = kwargs.get('occupation', instance.occupation) if occupation: occupation = Validation.validate_occupation(occupation) instance.age_from = kwargs.get('age_from', instance.age_from) instance.age_to = kwargs.get('age_to', instance.age_to) instance.height_from = kwargs.get('height_from', instance.height_from) instance.height_to = kwargs.get('height_to', instance.height_to) instance.physical_status = kwargs.get('physical_status', instance.physical_status) instance.body_type = kwargs.get('body_type', instance.body_type) instance.eating_habits = kwargs.get('eating_habits', instance.eating_habits) instance.drinking_habits = kwargs.get('drinking_habits', instance.drinking_habits) instance.smoking_habits = kwargs.get('smoking_habits', instance.smoking_habits) instance.mother_tongue = mother_tongue instance.religion = religion instance.caste = caste instance.raasi = raasi instance.sub_caste = sub_caste instance.star = star instance.highest_education = highest_education instance.employed_in = kwargs.get('employed_in', instance.employed_in) instance.occupation = occupation instance.income_from = kwargs.get('income_from', instance.income_from) instance.income_to = kwargs.get('income_to', instance.income_to) instance.dosham = kwargs.get('dosham', instance.dosham) instance.about_partner = kwargs.get('about_partner', instance.about_partner) instance.save() status='success' message = 'Partner details updated!' except Exception as e: status = 'error' message = e return UpdatePartner(status=status, message=message)