예제 #1
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': '验证短信成功'
            }
        )
예제 #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
예제 #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': '修改密码成功!'})
예제 #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': '更换手机号成功'})
예제 #5
0
 def save_user_profile(self, user):
     company_name = self.cleaned_data['company_name']
     phone = self.cleaned_data['phone']
     user_profile = UserProfile(
         user=user,
         is_review=True,
         ip=self.request.environ['REMOTE_ADDR'],
         user_email=self.cleaned_data['user_email'],
         name=self.cleaned_data['name'],
         phone=phone,
         qq=self.cleaned_data['qq'],
         company_name=company_name,
     )
     company = Company(
         company_name=company_name,
         user=user,
     )
     company.save()
     company.category.add(*self.cleaned_data['select_fields'])
     company.save()
     SmsCode.delete_cache_code(phone, 'AccountReg')
     return user_profile
예제 #6
0
 def save_user_profile(self, user):
     company_name = self.cleaned_data['company_name']
     phone = self.cleaned_data['phone']
     user_profile = UserProfile(
         user=user,
         is_review=True,
         ip=self.request.environ['REMOTE_ADDR'],
         user_email=self.cleaned_data['user_email'],
         name=self.cleaned_data['name'],
         phone=phone,
         qq=self.cleaned_data['qq'],
         company_name=company_name,
     )
     company = Company(
         company_name=company_name,
         user=user,
     )
     company.save()
     company.category.add(*self.cleaned_data['select_fields'])
     company.save()
     SmsCode.delete_cache_code(phone, 'AccountReg')
     return user_profile
예제 #7
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': '验证短信成功'})
예제 #8
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': '修改密码成功!'
            }
        )
예제 #9
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': '更换手机号成功'
            }
        )
예제 #10
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