Ejemplo n.º 1
0
def auth_register():
    error = None
    # #############################################################
    # TODO: Add form input validation and sanitize everything and 
    #        add bcrypt support
    if request.method == 'POST':
        uname       = str(request.form['username'])
        pw          = str(request.form['password'])
        pw2         = str(request.form['password2'])
        email       = str(request.form['email'])
        unc_email   = str(request.form['uncc_email'])
        fname       = str(request.form['firstname'])
        lname       = str(request.form['lastname'])
        nick        = str(request.form['nickname'])
        degree_prog = int(request.form['degree_program'])

        if len(uname) < 5:
            flash('Username is too short: must be longer than five characters', 'Error')
            return render_template('register.html', 
                    error=error,
                    degrees=app.config['DEGREE_PROGRAMS'])

        quser = User.query.filter_by(username = uname).first()
        qemail = User.query.filter_by(uncc_email = unc_email).first()
        
        if (quser is None) and (qemail is None):
            if pw == pw2: # basic password validation
                # generate password hash 
                passwd = hashpw(pw, gensalt())
                
                usr = User(uname, passwd, email)
                usr.set_fullname(fname,lname)
                usr.set_uncc_email(unc_email)
                usr.set_nickname(nick)
                usr.set_degree_program(degree_prog)

                db.session.add(usr)
                db.session.commit()

                flash('User created: You may now login.', 'Message')

                return default_view()
            else:
                flash('Passwords do not math', 'Error')
        else:
            flash('Username or Email already in use.', 'Error')
    return default_view('user/register.html')
Ejemplo n.º 2
0
base_app.db.session.commit()

admin_uname = base_app.config['DEFAULT_ADMIN_USER'][0]
admin_pwhash = base_app.config['DEFAULT_ADMIN_USER'][1]
admin_email = base_app.config['DEFAULT_ADMIN_USER'][2]
admin_umail = base_app.config['DEFAULT_ADMIN_USER'][3]

admin_fname = base_app.config['DEFAULT_ADMIN_USER'][4]
admin_lname = base_app.config['DEFAULT_ADMIN_USER'][5]
admin_nickname = base_app.config['DEFAULT_ADMIN_USER'][6]

usr = User( admin_uname, admin_pwhash, admin_email )

usr.set_fullname( admin_fname, admin_lname )
usr.set_nickname( admin_nickname )
usr.set_uncc_email( admin_umail )

usr.add_role('admin')

base_app.db.session.add(usr)

# #############################################################################
# Section: module specific configuration and initial population

from base import register_content_container

# #############################################################################
# Module: organization
# Synop: Populate the UserOffice table with the contents provided in config

from modules.organization.models import Office