def post(self):
        data = login_parser.parse_args()
        msisdn = data['msisdn']
        current_user = UserModel.find_by_msisdn(msisdn)

        if not current_user:
            return {
                'message':
                'User with MSISDN {} doesn\'t exist. Please register'.format(
                    msisdn)
            }, 401

        if current_user.password_status == PASSWORD_STATUS['USED']:
            return {
                'message': 'Your password is not valid. Please register again'
            }, 401

        if UserModel.verify_hash(data['password'], current_user.password):
            access_token = create_access_token(identity=msisdn)
            refresh_token = create_refresh_token(identity=msisdn)
            current_user.password_status = PASSWORD_STATUS['USED']
            current_user.update_data()
            return {
                'message': 'Logged in as {}'.format(current_user.msisdn),
                'access_token': access_token,
                'refresh_token': refresh_token
            }, 200
        else:
            return {'message': 'Wrong credentials'}, 401
    def post(self):
        data = registration_parser.parse_args()
        msisdn = data['msisdn']
        if is_msisdn_valid(msisdn):

            current_user = UserModel.find_by_msisdn(msisdn)
            if current_user:
                if current_user.password_status == PASSWORD_STATUS['USED']:
                    password = gen_password()
                    current_user.password = UserModel.generate_hash(password)
                    current_user.password_status = PASSWORD_STATUS['NEW']
                    current_user.update_data()

                    password_history_note = PasswordHistoryModel(
                        msisdn=current_user.msisdn,
                        password=current_user.password)
                    password_history_note.add()

                    send_password_sms_to_user(password, msisdn)
                    return {
                        'message':
                        'New password for MSISDN {} was created'.format(msisdn)
                    }, 200

                if current_user.password_status == PASSWORD_STATUS['NEW']:
                    password = gen_password()
                    current_user.password = UserModel.generate_hash(password)
                    current_user.update_data()

                    password_history_note = PasswordHistoryModel(
                        msisdn=current_user.msisdn,
                        password=current_user.password)
                    password_history_note.add()

                    send_password_sms_to_user(password, msisdn)
                    return {
                        'message':
                        'New password for MSISDN {} was created'.format(msisdn)
                    }, 200

            else:
                password = gen_password()

                new_user = UserModel(
                    msisdn=msisdn, password=UserModel.generate_hash(password))
                password_history_note = PasswordHistoryModel(
                    msisdn=new_user.msisdn, password=new_user.password)

                try:
                    new_user.save_to_db()
                    password_history_note.add()
                    send_password_sms_to_user(password, msisdn)
                    return {
                        'message':
                        'New password for MSISDN {} was created'.format(msisdn)
                    }, 200
                except:
                    return {'message': 'Internal error'}, 500
        else:
            return {'message': 'Wrong format for MSISDN'}, 400