Exemple #1
0
    def recover_password_get(self):
        if web.ctx.query == '':
            qs = dict()
        else:
            # XXX: http://bugs.python.org/issue8136
            qs = parse_qs(urllib.unquote(web.ctx.query[1:]).encode('latin-1').decode('utf-8'))

        if not (qs.has_key('id') and qs.has_key('key')):
            return util.render().error(error_message = _('INVALID_LINK'),
                    help_context = 'error')
        user_id = qs['id'][0]
        key = qs['key'][0]
        uid = user._get_uid_from_username(user_id)
        if uid < 0:
            return util.render().error(error_message = _('INVALID_USERNAME'),
                    help_context = 'error')
        if user.get_password_salt(uid) != key:
            return util.render().error(error_message = _('INVALID_PASSWORD_KEY'),
                    help_context = 'error')

        self.session_set(user_id)
        web.ctx.session.persistent = False
        user.update_last_login(uid, web.ctx.ip)
        new_pw = user.generate_random_password()
        user.update_password(uid, new_pw)
        return util.render().error(error_message = _('Your temporary password is "%s"(case-sensitive). Change password now.') % new_pw,
                error_class = _('Information'))
Exemple #2
0
    def lost_login_post(self):
        data = web.input()
        recaptcha_url = 'http://www.google.com/recaptcha/api/verify'
        recaptcha_data = dict(challenge = data.recaptcha_challenge_field,
                response = data.recaptcha_response_field,
                remoteip = web.ctx.ip,
                privatekey = config.recaptcha_private_key)
        req = urllib2.Request(recaptcha_url, urllib.urlencode(recaptcha_data))
        response = urllib2.urlopen(req)
        page = response.read().split('\n')
        if page[0] == 'false':
            if page[1].strip() == 'incorrect-captcha-sol':
                return util.render().error(error_message = _('INCORRECT_CAPTCHA'), help_context='error')
            else:
                return util.render().error(error_message = _('CAPTCHA_ERROR'), help_context='error')
        found_users = user.get_user_from_email(data.email)
        if not found_users:
            return util.render().error(error_message = _('NO_SUCH_MAIL_ADDRESS'), help_context='error')
        salt_string = ''
        for u in found_users:
            salt = user.get_password_salt(u.uSerial)
            salt_string = salt_string + '* User %s: http://noah.kaist.ac.kr/+recover_password?id=%s&key=%s\n' % (u.uId, u.uId, salt)
        message_title = _('NOAH password recovery')
        message_body = _('''Dear NOAH user,

Some user on IP %s requested new password of your account(s). Following list contains your account(s). Click on the corresponding link for recovering password of account.

%s

If you did not requested password recovery, then please log in into your account. This link will not be vaild after logging into the account.''') % (web.ctx.ip, salt_string)
        mail.mail(data.email, message_title, message_body)
        return util.render().error(error_message = _('Message Sent. Please follow instructions on the message.'),
                error_class = _('Information'))