Esempio n. 1
0
def start_password_reset(ctx: rest.Context,
                         params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    if not user.email:
        raise errors.ValidationError(
            'User %r hasn\'t supplied email. Cannot reset password.' %
            (user_name))
    token = auth.generate_authentication_token(user)

    if 'SERVER_NAME' in ctx.env:
        url = ctx.env['SERVER_NAME'].rstrip('/')
    elif 'HTTP_ORIGIN' in ctx.env:
        url = ctx.env['HTTP_ORIGIN'].rstrip('/')
    elif 'HTTP_HOST' in ctx.env:
        url = ctx.env['HTTP_HOST'].rstrip('/')
    else:
        url = ''
    url += '/password-reset/%s:%s' % (user.name, token)

    mailer.send_mail('noreply@%s' % config.config['name'], user.email,
                     MAIL_SUBJECT.format(name=config.config['name']),
                     MAIL_BODY.format(name=config.config['name'], url=url))

    return {}
Esempio n. 2
0
def start_password_reset(ctx: rest.Context,
                         params: Dict[str, str]) -> rest.Response:
    user_name = params["user_name"]
    user = users.get_user_by_name_or_email(user_name)
    if not user.email:
        raise errors.ValidationError(
            "User %r hasn't supplied email. Cannot reset password." %
            (user_name))
    token = auth.generate_authentication_token(user)

    if config.config["domain"]:
        url = config.config["domain"]
    elif "HTTP_ORIGIN" in ctx.env:
        url = ctx.env["HTTP_ORIGIN"].rstrip("/")
    elif "HTTP_REFERER" in ctx.env:
        url = ctx.env["HTTP_REFERER"].rstrip("/")
    else:
        url = ""
    url += "/password-reset/%s:%s" % (user.name, token)

    mailer.send_mail(
        config.config["smtp"]["from"],
        user.email,
        MAIL_SUBJECT.format(name=config.config["name"]),
        MAIL_BODY.format(name=config.config["name"], url=url),
    )

    return {}
Esempio n. 3
0
 def get(self, _ctx, user_name):
     ''' Send a mail with secure token to the correlated user. '''
     user = users.get_user_by_name_or_email(user_name)
     if not user.email:
         raise errors.ValidationError(
             'User %r hasn\'t supplied email. Cannot reset password.' %
             (user_name))
     token = auth.generate_authentication_token(user)
     url = '%s/password-reset/%s:%s' % (
         config.config['base_url'].rstrip('/'), user.name, token)
     mailer.send_mail('noreply@%s' % config.config['name'], user.email,
                      MAIL_SUBJECT.format(name=config.config['name']),
                      MAIL_BODY.format(name=config.config['name'], url=url))
     return {}
Esempio n. 4
0
def start_password_reset(_ctx: rest.Context,
                         params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    if not user.email:
        raise errors.ValidationError(
            'User %r hasn\'t supplied email. Cannot reset password.' %
            (user_name))
    token = auth.generate_authentication_token(user)
    url = '%s/password-reset/%s:%s' % (config.config['base_url'].rstrip('/'),
                                       user.name, token)
    mailer.send_mail('noreply@%s' % config.config['name'], user.email,
                     MAIL_SUBJECT.format(name=config.config['name']),
                     MAIL_BODY.format(name=config.config['name'], url=url))
    return {}
Esempio n. 5
0
def start_password_reset(_ctx: rest.Context,
                         params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    if not user.email:
        raise errors.ValidationError(
            '사용자 %r님은 이메일 주소를 등록하지 않았습니다. 비밀번호를 재설정할 수 없습니다.' % (user_name))
    token = auth.generate_authentication_token(user)
    url = '%s/password-reset/%s:%s' % (config.config['base_url'].rstrip('/'),
                                       user.name, token)
    mailer.send_mail(
        formataddr((str(Header(config.config['smtp']['user_display'],
                               'utf-8')), config.config['smtp']['user'])),
        user.email, MAIL_SUBJECT.format(name=config.config['name']),
        MAIL_BODY.format(name=config.config['name'], url=url))
    return {}
Esempio n. 6
0
def start_password_reset(_ctx, params):
    ''' Send a mail with secure token to the correlated user. '''
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    if not user.email:
        raise errors.ValidationError(
            'User %r hasn\'t supplied email. Cannot reset password.' % (
                user_name))
    token = auth.generate_authentication_token(user)
    url = '%s/password-reset/%s:%s' % (
        config.config['base_url'].rstrip('/'), user.name, token)
    mailer.send_mail(
        'noreply@%s' % config.config['name'],
        user.email,
        MAIL_SUBJECT.format(name=config.config['name']),
        MAIL_BODY.format(name=config.config['name'], url=url))
    return {}
Esempio n. 7
0
def start_password_reset(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    if not user.email:
        raise errors.ValidationError(
            'User %r hasn\'t supplied email. Cannot reset password.' % (
                user_name))
    token = auth.generate_authentication_token(user)

    if 'HTTP_ORIGIN' in ctx.env:
        url = ctx.env['HTTP_ORIGIN'].rstrip('/')
    else:
        url = ''
    url += '/password-reset/%s:%s' % (user.name, token)

    mailer.send_mail(
        'noreply@%s' % config.config['name'],
        user.email,
        MAIL_SUBJECT.format(name=config.config['name']),
        MAIL_BODY.format(name=config.config['name'], url=url))

    return {}