def create_test_user(self): username = "******" password = "******" hashed_password = bcrypt.hashpw(password.encode('utf8'), bcrypt.gensalt()) with db_connection.create_connection(self.database_path) as conn: user_id = db_connection.create_user(conn, (username, hashed_password)) self.login_session.user = login.User(user_id, username, hashed_password) self.login_session.logged_in = True
def login(): if os.environ.get('CERN_DUMMY_LOGIN',False): next_url = request.args.get('next') or url_for('home') login_user(login_module.User( 'lheinric_dummy', 'Lukas', 'Heinrich', 'ATLAS', )) return redirect(next_url) redirect_uri = os.environ['CERN_OAUTH_BASEURL'] + url_for('oauth_redirect') return oauth_app.authorize_redirect(redirect_uri)
def oauth_redirect(resp): next_url = request.args.get('next') or url_for('home') if resp is None: return redirect(next_url) data = user_data(resp['access_token']) data = extract_user_info(data) print 'USER!!', data if 'experiment' in data and data['experiment'] == 'ATLAS': user = login_module.User( data['username'], data['firstname'], data['lastname'], data['experiment'], ) login_user(user) return redirect(next_url)
from bottle import request,static_file,run,route,redirect,response import update_records as ur import json import login a=ur.Add_Data() u=login.User() root_dir='/home/skylark/' @route('/') def home(filename='index.html'): response.set_cookie('logged_in','') return static_file(filename,root=root_dir) @route('/register') def show_register(filename='register.html'): return static_file(filename,root=root_dir) @route('/register',method="POST") def register(): email=request.forms.get('email') name=request.forms.get('name') password=request.forms.get('password') if(u.add_user(name,email,password)==200): response.set_cookie('logged_in','true') redirect('/') else: redirect('/login')
def load_user(user_id): with db().cursor() as cur: cur.execute("select 1 from users where user_email = %s", (user_id, )) if cur.fetchone() != None: return login.User(True, True, False, user_id)
def load_user(user_id): user = login.User(user_id) return user