Exemplo n.º 1
0
 def login(self, request, *args, **kwargs):
     ser = serializer.ManyLoginSerilaize(data=request.data)
     if ser.is_valid():
         token = ser.context["token"]
         username = ser.context["user"].username
         return APIResponse(token=token, username=username)
     return APIResponse(code=0, msg=ser.errors)
Exemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     ser = self.get_serializer(data=request.data)
     if ser.is_valid():
         ser.save()
         return APIResponse(code=1, msg='注册成功')
     else:
         return APIResponse(code=0, msg=ser.errors)
Exemplo n.º 3
0
 def code_login(self, request, *args, **kwargs):
     ser = serializer.CodeUserSerilaizer(data=request.data)
     if ser.is_valid():
         token = ser.context['token']
         username = ser.context['username']
         return APIResponse(token=token, username=username)
     else:
         return APIResponse(code=0, msg=ser.errors)
Exemplo n.º 4
0
 def code_login(self, request, *args, **kwargs):
     ser = serializer.CodeLoginSerilaizer(data=request.data)
     if ser.is_valid(raise_exception=True):
         token = ser.context["token"]
         username = ser.context["user"].username
         return APIResponse(token=token, username=username)
     else:
         return APIResponse(code=0, msg=ser.errors)
Exemplo n.º 5
0
 def check_phone(self, request, *args, **kwargs):
     phone = request.data.get('phone')
     if not re.match('^1[3-9][0-9]{9}$', phone):
         return APIResponse(code=0, msg='手机号格式错误')
     try:
         models.User.objects.get(phone=phone)
         return APIResponse(msg='True')
     except:
         return APIResponse(code=0, msg='手机号不存在')
Exemplo n.º 6
0
 def check(self, request, *args, **kwargs):
     telephone = request.query_params.get("telephone")
     if not re.match("^1[3-9][0-9]{9}", telephone):
         return APIResponse(code=0, msg="手机号不合法")
     try:
         models.User.objects.get(telephone=telephone)
         return APIResponse(code=1)
     except Exception:
         return APIResponse(code=0, msg="手机号不存在")
Exemplo n.º 7
0
 def check_telephone(self, request, *args, **kwargs):
     import re
     telephone = request.query_params.get('telephone')
     if not re.match('^1[3-9][0-9]{9}', telephone):
         return APIResponse(code=0, msg='手机号不合法')
     try:
         models.User.objects.get(telephone=telephone)
         return APIResponse(code=1)
     except:
         return APIResponse(code=0, msg='手机号不存在')
Exemplo n.º 8
0
    def send(self, request, *args, **kwargs):
        from luffyapi.libs.tx_sms import get_code, send_message
        from django.core.cache import cache  # 如不设置缓存默认保存在内存中
        telephone = request.query_params.get("telephone")
        code = get_code()
        result = send_message(telephone, code)

        cache.set(settings.PHONE_CACHE_KEY % telephone, code, 180)  # 存储三分钟
        if result:
            return APIResponse(code=1, msg='验证码发送成功')
        else:
            return APIResponse(code=0, msg='验证码发送失败')
Exemplo n.º 9
0
 def send(self, request, *args, **kwargs):
     from luffyapi.libs.tencent_msg.send import get_code, send_msg
     from django.core.cache import cache
     from django.conf import settings
     telephone = request.query_params.get('telephone')
     if not re.match('^1[3-9][0-9]{9}', telephone):
         return APIResponse(code=0, msg='手机号不合法')
     code = get_code()
     result = send_msg(telephone, code)
     cache.set(settings.PHONE_CACHE_KEY % telephone, code, 180)
     if result:
         return APIResponse(code=1, msg='验证码发送成功')
     else:
         return APIResponse(code=0, msg='验证码发送失败')
Exemplo n.º 10
0
 def login(self, request, *args, **kwargs):
     ser = serializer.UserSerilaizer(data=request.data)
     if ser.is_valid():
         token = ser.context['token']
         # ser.context['user'] 是user对象
         username = ser.context['user'].username
         # {'code':1
         #  msg:'chengg'
         #  token:'sdfasdf'
         #  username:'******'
         #  }
         return APIResponse(token=token, username=username)
     else:
         return APIResponse(code=0, msg=ser.errors)
Exemplo n.º 11
0
 def send_phone(self, request, *args, **kwargs):
     from luffyapi.libs.tx_sms import get_code, send
     from django.core.cache import cache
     from luffyapi.settings import const
     phone = request.data.get('phone')
     if not re.match('1[3-9][0-9]{9}', phone):
         return APIResponse(code=0, msg='手机号不合法')
     code = get_code()
     print(code)
     res = send(phone, code)
     # res =1
     #'sms_code_%s'% phone
     cache.set(const.PHONE_KEY % phone, code, 300)
     if res:
         return APIResponse(code=1, msg="发送成功")
     else:
         return APIResponse(code=0, msg='发送失败')
Exemplo n.º 12
0
 def send(self, request, *args, **kwargs):
     '''
     发送验证码接口
     :return:
     '''
     import re
     from luffyapi.libs.tx_sms import get_code, send_message
     from django.core.cache import cache
     from django.conf import settings
     telephone = request.query_params.get('telephone')
     if not re.match('^1[3-9][0-9]{9}', telephone):
         return APIResponse(code=0, msg='手机号不合法')
     code = get_code()
     result = send_message(telephone, code)
     # 验证码保存(保存到哪?)
     # sms_cache_%s
     cache.set(settings.PHONE_CACHE_KEY % telephone, code, 180)
     if result:
         return APIResponse(code=1, msg='验证码发送成功')
     else:
         return APIResponse(code=0, msg='验证码发送失败')
Exemplo n.º 13
0
 def _get_user(self,attrs):
     from django.core.cache import cache
     from luffyapi.settings import const
     phone=attrs.get('phone')
     code=attrs.get('code')
     if not re.match('1[3-9][0-9]{9}',phone):
         return APIResponse(code=0,msg='手机号不合法')
     c_code=cache.get(const.PHONE_KEY % phone)
     user=models.User.objects.filter(phone=phone).first()
     if user:
         if c_code == code:
             return user
         else:
             raise ValidationError('验证码错误')
     else:
         raise ValidationError('用户名不存在')
Exemplo n.º 14
0
 def create(self, request, *args, **kwargs):
     response = super().create(request, *args, **kwargs)
     username = response.data.get('username')
     return APIResponse(code=1, msg='注册成功', username=username)