Example #1
0
def registration(operation,
                 phone,
                 OTP=None,
                 first_name=None,
                 last_name=None,
                 email=None,
                 password=None):
    if operation == 'VERIFY_USER_REGISTRATION_SEND_OTP':
        data = UserProfile.phone_input(operation, phone)
        context = {'user_registered': data['user_registered']}
        return context
    elif operation == 'USER_SIGNIN':
        data = get_user_from_phone(phone=phone,
                                   phone_otp=OTP,
                                   password=password)
        return data
    elif operation == 'USER_SIGNUP':
        user = UserProfile.create_with_phone(phone=phone,
                                             otp=OTP,
                                             email=email,
                                             first_name=first_name,
                                             last_name=last_name).user
        if password:
            user.set_password(password)
            user.save()
        token = jwt_utils.get_token_for_user(user)
        data = {'username': user.username, 'token': token, 'user_id': user.id}
        return data
Example #2
0
def create_user_from_phone(phone,
                           first_name,
                           last_name,
                           password1,
                           password2,
                           otp=None,
                           email=None,
                           username=None):
    if password1 != password2:
        raise_error('ERR-AUTH-UNMATCHED-PASSWORD')
    user = UserProfile.create_with_phone(phone=phone,
                                         email=email,
                                         first_name=first_name,
                                         last_name=last_name,
                                         username=username,
                                         otp=otp).user
    user.set_password(password1)
    user.save()
    token = jwt_utils.get_token_for_user(user)
    data = {'username': user.username, 'token': token, 'user_id': user.id}
    return data