Exemple #1
0
    def resend_activation_code_to_phone_number(phone_number):
        # validate phone number
        if re.match(User.Constants.phone_regex, phone_number) is None:
            return Tools.Result(False, Tools.errors('NA'))

        # make sure user is registered and in not confirmed status
        valid = user_collection.find_one({'PhoneNumber': phone_number},
                                         {'_id': 1}) is not None

        if not valid:
            return Tools.Result(False, Tools.errors('NA'))

        # generate an activation code
        activation_code = User.generate_activation_code()

        # store new generated code
        user_collection.update_one({'PhoneNumber': phone_number}, {
            '$set': {
                'Update_at': datetime.now(),
                'Code.Code': activation_code,
                'Code.Is_Used': False
            }
        })
        # send code to phone number
        sending_result = send_code_phone_number(phone_number, activation_code)

        return sending_result
Exemple #2
0
    def login(phone_number):

        # validate phone number
        if User.validate_phone(phone_number) is None:
            return Tools.Result(False, Tools.errors('NA'))

        # make sure user with specified phone number is registered and confirmed
        user_object = user_collection.find_one(
            {'PhoneNumber': phone_number
             # 'Status': 'Confirm'
             },
            {'_id': 1})

        if user_object is None:
            return Tools.Result(False, Tools.errors('INF'))

        # generate activation code
        activation_code = User.generate_activation_code()

        # send activation code to phone number
        activation_result = send_code_phone_number(phone_number,
                                                   activation_code)

        # parse result
        result_dict = json.loads(activation_result)

        # check whether sending sms was successful
        successful = result_dict['State']

        # if it failed -> forward the result
        if not successful:
            return activation_result

        user_collection.update_one(
            {'PhoneNumber': phone_number},
            {'$set': {
                'Code.Code': activation_code,
                'Code.Is_Used': False
            }})

        return Tools.Result(True, 'L')
Exemple #3
0
    def update_profile_info(user_id, name, birthdate):

        result = user_collection.update_one({'_id': ObjectId(user_id)}, {
            '$set': {
                'Name': name,
                'BirthDate': birthdate,
                'Update_at': datetime.now()
            }
        })

        if result.modified_count == 0:
            return Tools.Result(False, Tools.errors('INF'))
        else:
            return Tools.Result(True, 'd')
Exemple #4
0
    def login_verification(phone_number, verification_code):
        # validate phone number and activation code
        if (re.match(User.Constants.phone_regex, phone_number) is None
                or re.match(User.Constants.activation_code_regex,
                            str(verification_code)) is None):
            return Tools.Result(False, Tools.errors('NA'))

        # check whether user is registered and is assigned the specified activation code
        # also make sure code is not used before
        user_object = user_collection.find_one(
            {
                'PhoneNumber': phone_number,
                'Code.Code': int(verification_code),
                'Code.Is_Used': False
            }, {'_id': 1})

        if user_object is None:
            return Tools.Result(False, Tools.errors('INF'))

        # update user status to confirmed
        user_collection.update_one({'PhoneNumber': phone_number}, {
            '$set': {
                'Update_at': datetime.now(),
                'Status': 'Confirm',
                'Code.Is_Used': True,
                'IsActive': True
            }
        })

        token = Auth.add_token(user_id=str(user_object["_id"]))

        if not token:
            return Tools.Result(False, Tools.errors("FTGT"))

        response = {'Id': user_object["_id"], 'Token': token}

        return Tools.Result(True, Tools.dumps(response))
Exemple #5
0
    def complete_sign_up(phone_number, name=None, birthdate=None, gender=None):
        # validate phone number
        if User.validate_phone(phone_number) is None:
            return Tools.Result(False, Tools.errors('NA'))

        # make sure user with specified phone number is registered and confirmed
        user_object = user_collection.find_one(
            {'PhoneNumber': phone_number
             # 'Status': 'Confirm'
             },
            {'_id': 1})

        if user_object is None:
            return Tools.Result(False, Tools.errors('INF'))

        user_collection.update_one(
            {'PhoneNumber': phone_number},
            {'$set': {
                'Name': name,
                'Birthdate': birthdate,
                'Gender': gender
            }})

        return Tools.Result(True, 'd')