예제 #1
0
 def send_reset_pass_code(self, request):
     data = request.data.copy()
     email = data.get('email', None)
     if not email:
         raise exceptions.ParseError(_('Please provide email.'))
     user = UserService.get_by_email(email)
     token = default_token_generator.make_token(user)
     uid = urlsafe_base64_encode(force_bytes(user.pk))
     return Response({
         'uid': uid.decode('utf-8'),
         'token': token,
         'username': user.email
     })
예제 #2
0
 def send_reset_password_link(self, request):
     email = request.data.get('email', None)
     if not email:
         raise exceptions.ParseError(_('Please provide email.'))
     user = UserService.get_by_email(email)
     if not user:
         raise exceptions.NotFound(_('User not found.'))
     token = default_token_generator.make_token(user)
     uid = urlsafe_base64_encode(force_bytes(user.pk))
     EmailService.reset_link(token=token, uid=uid, user=user)
     return Response({
         "message":
         "A link with instruction has been sent to your email, please check your email to reset password."
     })
예제 #3
0
 def reset_by_code(self, request):
     email = request.data.get('email', None)
     if not email:
         raise exceptions.ParseError(_('Please provide email.'))
     user = UserService.get_by_email(email)
     if not user:
         raise exceptions.NotFound(_('Email not found.'))
     token = default_token_generator.make_token(user)
     pin = Utils.id_generator(4)
     p = PinCode(pin=pin, user=user)
     p.save()
     EmailService.reset_pin(pin=pin, email=email)
     return Response({
         "message":
         "A link with instruction has been sent to your email, please check your email to reset password.",
         "uid": user.id
     })
예제 #4
0
 def validate(self, attrs):
     email = attrs.get('email')
     confirm_password = attrs.get('confirm_password')
     new_password = attrs.get('new_password')
     user_id = attrs.get('user_id')
     if (email or user_id) and confirm_password and new_password:
         if email:
             user = UserService.get_by_email(email)
         elif user_id:
             user = UserService.get_user(user_id)
         if user:
             user.set_password(new_password)
             user.save()
             attrs['user'] = user
             return attrs
         else:
             raise exceptions.ValidationError(_('User not found.'))
     else:
         raise exceptions.ValidationError(_('Must include password.'))