Beispiel #1
0
    def post(self):
        try:
            password = self.get_argument('password')
            confirm_password = self.get_argument('confirm_password')
            verify_code = self.get_argument('verify_code')
            telephone = self.get_argument('telephone')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        change_time = datetime.now()
        if password != confirm_password:
            return self.error(ENTERED_PASSWORD_DIFFER)

        if str(verify_code) != Verify.get_verify_code(RESET_PASSWORD_VERIFY_CODE_TYPE, telephone):
            return self.error(MISMATCHED_VERIFY_CODE)

        user = User.get_user_by_telephone(telephone)
        if not user:
            return self.error(TELEPHONE_NOT_REGISTER)

        password = encrypt_password(password)
        user.update(password=password, update_time=change_time)
        user_auth = UserAuth.get_by_user_id(user.id)
        user_auth.clear_access_token()
        notify_change_password.delay(user.id, change_time)
        return self.render({
            'status': 0,
        })
Beispiel #2
0
    def post(self, *args, **kwargs):
        try:
            telephone = self.get_argument('telephone')
            password = self.get_argument('password')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        if not verify_telephone(telephone):
            return self.error(PHONE_NOT_RIGHT)

        password = encrypt_password(password)
        user = User.get_user_by_telephone(telephone)
        if not user:
            return self.error(TELEPHONE_NOT_REGISTER)

        if password != user.password:
            return self.error(MISMATCHED_PASSWORD)

        try:
            access_token = gen_access_token(user.id)
            UserAuth.update_access_token(user.id, access_token)
            rst = {
                'status': 0,
                'data': {
                    'user': user.jsonify(),
                    'access_token': access_token,
                },
            }
            return self.render(rst)
        except Exception as e:
            logger.error(u'用户登录失败。telephone:[%s], Error:[%s]' % (telephone, e))
            return self.error(SYSTEM_ERROR)
Beispiel #3
0
    def post(self, *args, **kwargs):
        try:
            telephone = self.get_argument('telephone')
            password = self.get_argument('password')
            verify_code = self.get_argument('verify_code')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        if not verify_telephone(telephone):
            return self.error(PHONE_NOT_RIGHT)

        # 检测是否有相同手机号的用户
        exist_user_telephone = User.exists_user_by_telephone(telephone)
        if exist_user_telephone:
            return self.error(EXIST_USER_TELEPHONE)

        # 检测验证码是否正确
        if str(verify_code) != str(Verify.get_verify_code(REGISTER_VERIFY_CODE_TYPE, telephone)):
            return self.error(MISMATCHED_VERIFY_CODE)

        password = encrypt_password(password)
        try:
            user_id = User.add(telephone, password)
            user_amount = User.get_user_count()
            account = Account.add(user_id, 0.00)
            # UserIntegral.add(user_id, 0)
            # if user_amount <= 500:
            #     account.add_balance(10.00)
            #     PresentedBalance.add(user_id, 10.00, PRESENT_BEFORE_500)
            #
            # if int(telephone) in NEICE_TELEPHONES:
            #     account.add_balance(10.00)
            #     PresentedBalance.add(user_id, 10.00, PRESENT_NEICE)

            access_token = gen_access_token(user_id)
            UserAuth.add(user_id, access_token)
            user = User.get(user_id)
            rst = {
                'status': 0,
                'data': {
                    'user': user.jsonify(),
                    'access_token': access_token,
                },
            }

            return self.render(rst)
        except Exception as e:
            logger.error(u'添加用户失败。Error:%s', e)
            return self.error(SYSTEM_ERROR)
Beispiel #4
0
    def post(self):
        try:
            user_id = self.get_argument('user_id')
            payment_code = self.get_argument('payment_code')
            confirm_payment_code = self.get_argument('confirm_payment_code')
            verify_code = self.get_argument('verify_code')
            telephone = self.get_argument('telephone')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        if not verify_telephone(telephone):
            return self.error(PHONE_NOT_RIGHT)

        user = User.get(user_id)
        if not user:
            return self.error(USER_NOT_FOUND)

        if str(payment_code) != str(confirm_payment_code):
            return self.error(ENTERED_PAYMENT_CODE_DIFFER)

        if str(verify_code) != Verify.get_verify_code(RESET_PAYMENT_CODE_TYPE, telephone):
            return self.error(MISMATCHED_VERIFY_CODE)

        payment_code = encrypt_password(payment_code)
        payment_code_obj = UserPaymentCode.get_by_user(user_id)
        if not payment_code_obj:
            try:
                UserPaymentCode.add(user_id, payment_code)
                handle_set_payment_code_integral.delay(user_id)
            except Exception as e:
                logger.error(u'添加用户支付密码失败。Error:[%s]' % e)
                return self.error(SYSTEM_ERROR)
        else:
            try:
                change_time = datetime.now()
                payment_code_obj.update_payment_code(payment_code, change_time)
                notify_change_payment_code.delay(user_id, change_time)
            except Exception as e:
                logger.error(u'更新用户密码失败。Error:[%s]' % e)
                return self.error(SYSTEM_ERROR)

        return self.render({
            'status': 0,
            'data': {
                'has_payment_code': True,
            }
        })
Beispiel #5
0
    def post(self):
        try:
            user_id = self.get_argument('user_id')
            payment_code = str(self.get_argument('payment_code'))
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        user_payment_code = UserPaymentCode.get_by_user(user_id)
        if not user_payment_code:
            return self.error(PAYMENT_CODE_NOT_EXISTS)

        payment_code = encrypt_password(payment_code)
        if payment_code != str(user_payment_code.payment_code):
            return self.error(PAYMENT_CODE_ERROR)

        return self.render({
            'status': 0
        })
Beispiel #6
0
    def post(self):
        try:
            user_id = self.get_argument('user_id')
            payment_code = self.get_argument('payment_code')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        payment_code = encrypt_password(payment_code)
        payment_code_obj = UserPaymentCode.get_by_user(user_id)
        if payment_code_obj:
            return self.error(ACCESS_NOT_ALLOWED)
        else:
            try:
                UserPaymentCode.add(user_id, payment_code)
                handle_set_payment_code_integral.delay(user_id)
            except Exception as e:
                logger.error(u'添加用户支付密码失败。Error:[%s]' % e)
                return self.error(SYSTEM_ERROR)

        return self.render({
            'status': 0,
        })