コード例 #1
0
ファイル: daybook.py プロジェクト: siwells/set09103
def root():
    if request.method == 'POST':
        button = request.form['button']
        if button  == 'join':
            if request.form['password'] == request.form['password_confirmation']:
                if users.get_uuid(userdb, request.form['email']) is not None:
                    
                    msg = (gettext("An account already exists for that email address. Please either use another email address or use the recover password feature."))
                    app.logger.warn("Account already exists for "+str(request.form['email']))
                else:

                    lang = request.accept_languages.best_match(LANGUAGES.keys())

                    uuid = users.add_user(userdb, request.form['email'], request.form['password'], request.form['first_name'], request.form['last_name'], lang)
                
                    subject = gettext("SUPERHUB Project :: New Journey Diary Account")
                    content = gettext("A new SUPERHUB Journey Diary account has been created for the following email address: {kwarg}. You should now be able to log into the journey diary and record your journeys.").format(kwarg=request.form['email'])

                    # Added a toggle for the email confirmation service, as it was causing problems on my server. You can re-enable it in the config.
                    if (app.config['send_mail'] == "True"):
                        mail.send(app.config['email_address'], app.config['email_password'], request.form['email'], subject, content)
                        msg = gettext("An email has been sent to {kwarg} so that you can verify your email address. However you can log into your account immediately.").format(kwarg=request.form['email'])
                    else:
                        msg = gettext("A confirmation email could not be sent at this time. You can still sign in to your account right away")
                        app.logger.warn("Confirmation email was not sent to " +str(request.form['email'])+" as outgoing mail is disabled. See config.")
                    
                    logline = { 'type':'New user reqistration', 'timestamp': str(datetime.now().isoformat()), 'data': {'email': request.form['email'], 'uuid':uuid}, 'payload': None}                    
                    app.logger.info( json.dumps(logline) )
            else:
                msg = gettext("The supplied passwords do not match. Please ensure that you type the same password into both the password box and the confirmation box.")

            flash(msg)
           
        elif button == 'login':
            if check_auth(request.form['email'], request.form['password']):
                session['email'] = request.form['email']
                session['uuid'] = users.get_uuid(userdb, session['email'])
                session['logged_in'] = True
                return redirect(request.args['next'] if 'next' in request.args else url_for('.dashboard'))
            
            msg = gettext("The supplied password was incorrect")
            flash(msg)
            return render_template('index.html')

    try:
        if session['cookie_notified']:
            return render_template('index.html')
    except KeyError:
        alertlist = [
            {
                "msg":gettext('This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies.'),
                "type":"cookie_notification",
            }
        ]
        return render_template('index.html', alertlist = alertlist)
コード例 #2
0
ファイル: daybook.py プロジェクト: siwells/daybook
def root():
    if request.method == 'POST':
        button = request.form['button']
        if button  == 'join':
            if request.form['password'] == request.form['password_confirmation']:
                if users.get_uuid(userdb, request.form['email']) is not None:
                    
                    msg = (gettext("An account already exists for that email address. Please either use another email address or use the recover password feature."))
                    app.logger.warn("Account already exists for "+str(request.form['email']))
                else:

                    lang = request.accept_languages.best_match(LANGUAGES.keys())

                    uuid = users.add_user(userdb, request.form['email'], request.form['password'], request.form['first_name'], request.form['last_name'], lang)
                
                    subject = gettext("SUPERHUB Project :: New Journey Diary Account")
                    content = gettext("A new SUPERHUB Journey Diary account has been created for the following email address: {kwarg}. You should now be able to log into the journey diary and record your journeys.").format(kwarg=request.form['email'])

                    mail.send(app.config['email_address'], app.config['email_password'], request.form['email'], subject, content)

                    msg = gettext("An email has been sent to {kwarg} so that you can verify your email address. However you can log into your account immediately.").format(kwarg=request.form['email'])
                    
                    logline = { 'type':'New user reqistration', 'timestamp': str(datetime.now().isoformat()), 'data': {'email': request.form['email'], 'uuid':uuid}, 'payload': None}                    
                    app.logger.info( json.dumps(logline) )
            else:
                msg = gettext("The supplied passwords do not match. Please ensure that you type the same password into both the password box and the confirmation box.")

            flash(msg)
           
        elif button == 'login':
            if check_auth(request.form['email'], request.form['password']):
                session['email'] = request.form['email']
                session['uuid'] = users.get_uuid(userdb, session['email'])
                session['logged_in'] = True
                return redirect(request.args['next'] if 'next' in request.args else url_for('.dashboard'))
            
            msg = gettext("The supplied password was incorrect")
            flash(msg)
            return render_template('index.html')

    try:
        if session['cookie_notified']:
            return render_template('index.html')
    except KeyError:
        alertlist = [
            {
                "msg":gettext('This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies.'),
                "type":"cookie_notification",
            }
        ]
        return render_template('index.html', alertlist = alertlist)
コード例 #3
0
def recover():
    if request.method == 'POST':
        uuid = users.get_uuid(userdb, request.form['email'])
        if uuid is not None:
            newpass = password.generate()
            if users.set_password(userdb, session['uuid'], newpass):
                subject = gettext("SUPERHUB Project :: New Password")
                content = gettext(
                    "The password for the following email address: {email} was reset. You should now be able to log into the journey diary and record your journeys using the password: {newpass}."
                ).format(email=request.form['email'], newpass=newpass)
                mail.send(app.config['email_address'],
                          app.config['email_password'], request.form['email'],
                          subject, content)

                msg = gettext("An email was sent to {arg}").format(
                    arg=request.form['email'])
            else:
                msg = gettext(
                    "We were not able to update the password for this account. Please contact [email protected]"
                )
        else:
            msg = gettext(
                "There is no SUPERHUB account associated with the email address:"
            )
        flash(msg)
        return redirect(url_for('.root'))
    return render_template('recover.html')
コード例 #4
0
ファイル: daybook.py プロジェクト: siwells/daybook
def recover():
    if request.method == 'POST':
        uuid = users.get_uuid(userdb, request.form['email'])
        if uuid is not None:
            newpass = password.generate()
            if users.set_password(userdb, session['uuid'], newpass):
                subject = gettext("SUPERHUB Project :: New Password")
                content = gettext("The password for the following email address: {email} was reset. You should now be able to log into the journey diary and record your journeys using the password: {newpass}.").format(email=request.form['email'], newpass=newpass)
                mail.send(app.config['email_address'], app.config['email_password'], request.form['email'], subject, content)

                msg = gettext("An email was sent to {arg}").format(arg=request.form['email'])
            else:
                msg = gettext("We were not able to update the password for this account. Please contact [email protected]")
        else:
                msg = gettext("There is no SUPERHUB account associated with the email address:")     
        flash(msg)
        return redirect(url_for('.root'))
    return render_template('recover.html')