コード例 #1
0
ファイル: security.py プロジェクト: swordXfish/lookwider
def save_new_user(request):
    login = request.POST['login']
    email = request.POST['email']

    if len(login) == 0 or len(email) == 0:
        return Response('Bad input', content_type='text/plain', status_int=500)

    try:
        exists = DBSession.query(User).filter(or_(User.login == login,
                                                  User.email == email)).count()
        if exists > 0:
            existing_user = DBSession.query(User).filter(User.login == login).first()
            return HTTPFound(location=route_url('show_user', request, id=existing_user.id))

        user = User(login, email)
        user.first_name = request.POST['first_name']
        user.last_name = request.POST['last_name']
        user.user_name = request.POST['user_name']
        user.password = request.POST['password']
        user.gender = request.POST['gender']
        user.created_date = datetime.datetime.now()
        user.last_login_date = datetime.datetime.now()

        DBSession.add(user)
        DBSession.flush()
        return HTTPFound(location=route_url('show_user', request, id=user.id))
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
コード例 #2
0
ファイル: initializedb.py プロジェクト: swordXfish/lookwider
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        user = User('super', '*****@*****.**')
        user.first_name = 'Super'
        user.last_name = 'Medved'
        user.password = '******'
        user.phone = '000-000-00-00'
        user.gender = 'male'
        user.user_name = 'Wader'
        user.created_date = datetime.datetime.now()
        user.last_login_date = datetime.datetime.now()
        DBSession.add(user)