def post(self, request):
        post_data = request.JSON
        action_name = post_data.get('action_name')
        code = post_data.get('code')
        mobile = post_data.get('mobile')

        ret = SmsCode.vaild_sms_code(
            code=code,
            mobile=mobile,
            action_name=action_name
        )
        if not ret:
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '验证码错误',
                    'errors': {
                        "code": [
                            '验证码错误',
                        ]
                    }
                }
            )

        return JsonResponse(
            {
                'status': 'ok',
                'msg': '验证短信成功'
            }
        )
Beispiel #2
0
 def clean_code(self):
     code = self.cleaned_data['code']
     phone = self.data['phone']
     if not SmsCode.vaild_sms_code(
             code=code, mobile=phone, action_name='AccountReg'):
         raise forms.ValidationError('验证码错误错误')
     return code
Beispiel #3
0
    def post(self, request):
        post_data = request.JSON
        mobile = post_data.get('mobile')
        code = post_data.get('code')
        password = post_data.get('password')
        re_password = post_data.get('re_password')

        if not error_phone(mobile) and not PinbotAccount.is_phone_bind(
                mobile=mobile):
            return JsonResponse({
                'status': 'error',
                'msg': '手机号未绑定,不能登录',
                'errors': {
                    "phone": ['手机号未绑定,不能登录']
                }
            })

        if password != re_password:
            return JsonResponse({
                'status': 'error',
                'msg': '前后密码不一致',
                'errors': {
                    "password": ['前后密码不一致']
                }
            })

        if not SmsCode.vaild_sms_code(
                mobile=mobile, code=code, action_name='ChangePwd'):
            return JsonResponse({
                'status': 'error',
                'msg': '短信验证码错误',
                'errors': {
                    "code": ['短信验证码错误']
                }
            })
        user_profile = PinbotAccount.get_profile(phone=mobile,
                                                 is_phone_bind=True)
        if not user_profile:
            return JsonResponse({
                'status': 'error',
                'msg': '账号错误',
                'errors': {
                    "phone": ['账号错误']
                }
            })

        if not PinbotAccount.change_user_pwd(user_id=user_profile.user.id,
                                             password=password):
            return JsonResponse({
                'status': 'error',
                'msg': '修改密码错误,请重试或者联系管理员!'
            })

        return JsonResponse({'status': 'ok', 'msg': '修改密码成功!'})
Beispiel #4
0
    def post(self, request):
        post_data = request.JSON
        user = request.user
        password = post_data.get('password')
        code = post_data.get('code')
        mobile = post_data.get('mobile')
        if PinbotAccount.is_phone_bind(mobile=mobile):
            return JsonResponse({
                'status': 'error',
                'msg': '手机号已绑定,不能继续绑定',
                'errors': {
                    "phone": ['手机号已绑定,不能继续绑定']
                }
            })

        user_profile = user.userprofile
        if not user_profile:
            return JsonResponse({
                'status': 'error',
                'msg': '账号错误',
                'errors': {
                    "phone": ['账号错误']
                }
            })

        if not SmsCode.vaild_sms_code(
                code=code, mobile=mobile, action_name='ChangeMobile'):
            return JsonResponse({
                'status': 'error',
                'msg': '短信验证码错误',
                'errors': {
                    "code": ['短信验证码错误']
                }
            })
        user = authenticate(username=user.username, password=password)

        if not user:
            return JsonResponse({
                'status': 'error',
                'msg': '用户名或密码错误',
                'errors': {
                    "password": ['用户名或密码错误']
                }
            })

        ret = PinbotAccount.update_user_mobile(user=user, mobile=mobile)
        if not ret:
            return JsonResponse({
                'status': 'error',
                'msg': '更换手机号失败,请重试或者联系管理员'
            })
        return JsonResponse({'status': 'ok', 'msg': '更换手机号成功'})
Beispiel #5
0
    def post(self, request):
        post_data = request.JSON
        action_name = post_data.get('action_name')
        code = post_data.get('code')
        mobile = post_data.get('mobile')

        ret = SmsCode.vaild_sms_code(code=code,
                                     mobile=mobile,
                                     action_name=action_name)
        if not ret:
            return JsonResponse({
                'status': 'error',
                'msg': '验证码错误',
                'errors': {
                    "code": [
                        '验证码错误',
                    ]
                }
            })

        return JsonResponse({'status': 'ok', 'msg': '验证短信成功'})
    def post(self, request):
        post_data = request.JSON
        mobile = post_data.get('mobile')
        code = post_data.get('code')
        password = post_data.get('password')
        re_password = post_data.get('re_password')

        if not error_phone(mobile) and not PinbotAccount.is_phone_bind(mobile=mobile):
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '手机号未绑定,不能登录',
                    'errors': {
                        "phone": [
                            '手机号未绑定,不能登录'
                        ]
                    }
                }
            )

        if password != re_password:
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '前后密码不一致',
                    'errors': {
                        "password": [
                            '前后密码不一致'
                        ]
                    }
                }
            )

        if not SmsCode.vaild_sms_code(
            mobile=mobile,
            code=code,
            action_name='ChangePwd'
        ):
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '短信验证码错误',
                    'errors': {
                        "code": [
                            '短信验证码错误'
                        ]
                    }
                }
            )
        user_profile = PinbotAccount.get_profile(phone=mobile, is_phone_bind=True)
        if not user_profile:
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '账号错误',
                    'errors': {
                        "phone": [
                            '账号错误'
                        ]
                    }
                }
            )

        if not PinbotAccount.change_user_pwd(
            user_id=user_profile.user.id,
            password=password
        ):
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '修改密码错误,请重试或者联系管理员!'
                }
            )

        return JsonResponse(
            {
                'status': 'ok',
                'msg': '修改密码成功!'
            }
        )
    def post(self, request):
        post_data = request.JSON
        user = request.user
        password = post_data.get('password')
        code = post_data.get('code')
        mobile = post_data.get('mobile')
        if PinbotAccount.is_phone_bind(mobile=mobile):
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '手机号已绑定,不能继续绑定',
                    'errors': {
                        "phone": [
                            '手机号已绑定,不能继续绑定'
                        ]
                    }
                }
            )

        user_profile = user.userprofile
        if not user_profile:
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '账号错误',
                    'errors': {
                        "phone": [
                            '账号错误'
                        ]
                    }
                }
            )

        if not SmsCode.vaild_sms_code(
            code=code,
            mobile=mobile,
            action_name='ChangeMobile'
        ):
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '短信验证码错误',
                    'errors': {
                        "code": [
                            '短信验证码错误'
                        ]
                    }
                }
            )
        user = authenticate(
            username=user.username,
            password=password
        )

        if not user:
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '用户名或密码错误',
                    'errors': {
                        "password": [
                            '用户名或密码错误'
                        ]
                    }
                }
            )

        ret = PinbotAccount.update_user_mobile(
            user=user,
            mobile=mobile
        )
        if not ret:
            return JsonResponse(
                {
                    'status': 'error',
                    'msg': '更换手机号失败,请重试或者联系管理员'
                }
            )
        return JsonResponse(
            {
                'status': 'ok',
                'msg': '更换手机号成功'
            }
        )
Beispiel #8
0
 def clean_code(self):
     code = self.cleaned_data['code']
     phone = self.data['phone']
     if not SmsCode.vaild_sms_code(code=code, mobile=phone, action_name='AccountReg'):
         raise forms.ValidationError('验证码错误错误')
     return code