Esempio n. 1
0
 def send_recovery_mail(self, request):
     """ send async recovery mail """
     key = Locker.deposit(self.id)
     recovery_url = request.build_absolute_uri(
         reverse('recover_password', args=(key, )))
     send_mail_async(title=_('Password recovery'),
                     receivers=[self.email],
                     message=RECOVERY_EMAIL_MSG.format(
                         name=self.name, recovery_url=recovery_url))
Esempio n. 2
0
 def send_confirmation_mail(self, request):
     """ send async confirmation mail """
     key = Locker.deposit(self.id)
     verification_url = request.build_absolute_uri(
         reverse('user_verification', args=(key, )))
     send_mail_async(title=_('Welcome to MootiroMaps'),
                     receivers=[self.email],
                     message=CONFIRMATION_EMAIL_MSG.format(
                         name=self.name, verification_url=verification_url))
Esempio n. 3
0
 def send_confirmation_mail(self, request):
     """ send async confirmation mail """
     key = Locker.deposit(self.id)
     verification_url = request.build_absolute_uri(
             reverse('user_verification', args=(key,)))
     send_mail_async(
         title=_('Welcome to MootiroMaps'),
         receivers=[self.email],
         message=CONFIRMATION_EMAIL_MSG.format(
             name=self.name,
             verification_url=verification_url))
Esempio n. 4
0
 def send_recovery_mail(self, request):
     """ send async recovery mail """
     key = Locker.deposit(self.id)
     recovery_url = request.build_absolute_uri(
             reverse('recover_password', args=(key,)))
     send_mail_async(
         title=_('Password recovery'),
         receivers=[self.email],
         message=RECOVERY_EMAIL_MSG.format(
             name=self.name,
             recovery_url=recovery_url))
Esempio n. 5
0
def user_verification(request, key=''):
    '''
    Displays verification needed message if no key provided, or try to verify
    the user by the given key.
    '''
    # user_root_url = reverse('user_root')
    if not key:
        return {'message': 'check_email'}
    user_id = Locker.withdraw(key=key)
    user = User.get_by_id(user_id)
    if not user:
        # invalid key => invalid link
        raise Http404
    if not user.is_active:
        user.is_active = True
        user.save()
    return {'message': 'activated'}
Esempio n. 6
0
def user_verification(request, key=''):
    '''
    Displays verification needed message if no key provided, or try to verify
    the user by the given key.
    '''
    # user_root_url = reverse('user_root')
    if not key:
        return {'message': 'check_email'}
    user_id = Locker.withdraw(key=key)
    user = User.get_by_id(user_id)
    if not user:
        # invalid key => invalid link
        raise Http404
    if not user.is_active:
        user.is_active = True
        user.save()
    return {'message': 'activated'}
Esempio n. 7
0
def recover_password(request, key=''):
    if not key:
        return {'error': 'Invalid key, check your e-mail'}

    if request.method == "POST":
        if not request.POST['email']:
            return {'error': _('You must provide your e-mail')}

        if not request.POST['password']:
            return {'error': _('You must provide a password')}

        if request.POST["password"] != request.POST["password_confirmation"]:
            return {'error': _('Passwords do not match')}

        user_id = Locker.withdraw(key=key)
        user = User.get_by_id(user_id)

        if not user:
            # invalid key => invalid link
            return {'error': _('Invalid key')}

        if user.email != request.POST['email']:
            return {'error': _('User email and verification key do not match')}

        user.set_password(request.POST['password'])
        user.save()

        auth_login(request, user)
        response = HttpResponseRedirect('/')

        # Use language from user settings
        lang_code = user.language
        if lang_code and translation.check_for_language(lang_code):
            if hasattr(request, 'session'):
                request.session['django_language'] = lang_code
            else:
                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)
        return response
    return {'key': key}