示例#1
0
def register_user():
    """
        Register user
        Renders: user/registration-successful.html
        Throws:
            - Malformed request error form.token is not the same as session.token
    """
    error = ''
    if request.form['token'] != session['token']:
        error = 'Malformed Request. Please try again!'
    user = AuthUser.query.filter_by(email=request.form['email']).first()
    if not error and user:
        error = 'Email already exists'

    if error:
        token = str(random.getrandbits(128))
        session['token'] = token
        return render_template('user/registration.html',
                               token=token,
                               error=error)
    session.pop('token')
    pw_hash = bcrypt.generate_password_hash(request.form['password'])
    new_user = AuthUser(request.form['first_name'], request.form['last_name'],
                        request.form['email'], pw_hash)
    db.session.add(new_user)
    student_role = UserRole.query.filter_by(name='STUDENT').first()
    new_has_user_role = HasUserRole(new_user.auth_user_id,
                                    student_role.user_role_id)
    db.session.add(new_has_user_role)
    db.session.commit()
    return redirect(url_for('user.get_login_form'))
示例#2
0
#!./flask/bin/python
# -*- coding: utf-8 -*-

from app import db
from app.models import AuthUser, Equipment, User, Department

u = AuthUser("admin", "passad")
u.role = 1
db.add(u)
db.commit()

u = AuthUser("user", "passus")
u.role = 0
db.add(u)
db.commit()

equipment = [
        ['Sys block', '123456', '123456'],
        ['Monitor', '214365', '214365'],
        ['Faks', '432165', '432165'],
        ['Scanner', '654321', '654321'],
        ['Sys block', '1324356', '1324356']
        ]

users = [
        ['Serg', 'Porokh'],
        ['Vasyl', 'Chereda'],
        ['Musiy', 'Storoguk']
        ]

departments = ['jur', 'it']
示例#3
0
#!./flask/bin/python
# -*- coding: utf-8 -*-

from app import db
from app.models import AuthUser, Equipment, User, Department

u = AuthUser("admin", "passad")
u.role = 1
db.add(u)
db.commit()

u = AuthUser("user", "passus")
u.role = 0
db.add(u)
db.commit()


us_quip = {
        (u'Порох', u'Сергій'): [
            [u'Системиний блок', '123456', '132465'],
            [u'Монітор', '123457', '132467'],
            [u'Факс', '123458', '132468']
            ],
        (u'Копайбіда', u'Олег'): [
            [u'Системиний блок', '123466', '132475'],
            [u'Монітор', '123477', '132477'],
            [u'Факс', '123478', '132478']
            ],
        (u'Череда', u'Василь'): [
            [u'Системиний блок', '123436', '132435'],
            [u'Монітор', '123437', '132437'],