コード例 #1
0
ファイル: setup.py プロジェクト: circlingthesun/Formative
def initialize_mongo(db):
    '''Creates indexes if they are not defined '''
                
    if (db.admin.find_one({"initialized": True}) != None):
        return

       
    # Create users
    new_user('*****@*****.**', 'letmein', db, ['standard', 'admin'])

        
    
    db.admin.insert({"initialized": True})
コード例 #2
0
def ajax_signup(request):
    '''Processes ajax signups'''

    email = None
    try:
        email = validators.Email().to_python(request.POST['email'])
    except Exception as e:
        return {'success':False, 'error':'Invalid email address'}

    password = base64.b16encode(os.urandom(4))
    user_id = new_user(email, password,
            request.db)
     
    # if user was created   
    if user_id:
        headers = remember(request, user_id)
        request.response.headerlist.extend(headers)

        mailer = request.registry['mailer']
        office_email = request.registry.settings['office.email']
        from_ = "%s <%s>" % ("Formative", office_email)
        
        body = """Thank your for signing up. Your password is: %s"""\
                % password

        message = Message(
                  subject='Account created',
                  sender=office_email,
                  recipients=[email],
                  body=body,
                  extra_headers = {"From": from_}
                  )
        mailer.send_immediately(message)
    else:
        return {
            "success": False,
            "error": '"%s" is already registered.' % email
        }
                    
    return {"success":True}
コード例 #3
0
def signup(request):
    '''Shows the signup page'''
    form = Form(request, schema=ForgotPasswordSchema)
        
    if form.validate():
        password = base64.b16encode(os.urandom(4))
        user_id = new_user(form.data['email'], password,
                request.db)
        
        # if user was created
        if user_id:
            headers = remember(request, user_id)


            mailer = request.registry['mailer']
            office_email = request.registry.settings['office.email']
            from_ = "%s <%s>" % ("Formative", office_email)
            
            body = """Thank your for signing up. Your password is: %s"""\
                    % password

            message = Message(
                      subject='Account created',
                      sender=office_email,
                      recipients=[form.data['email']],
                      body=body,
                      extra_headers = {"From": from_}
                      )
            
            mailer.send_immediately(message)

            request.session.flash('Signup successful.', queue='info')
            return HTTPFound(location = '/account', headers = headers)
        else:
            request.session.flash(
                    '"%s" is already registered.' % form.data['email'],
                    queue='error'
                    )  

    return {"renderer":FormRenderer(form)}