def __setup_db(): """ Setup the database and create a connection """ with __flask_app.app_context(): db.init_app(__flask_app) db.init_db() auth.register_user('root', 'root')
def post(self): with locks.global_lock: if not competition.allow_team_self_registration: self.write( render_template('reg_error.html', error=lc.get('registration_disabled'))) username = self.get_argument('username', None) password = self.get_argument('password', None) password_c = self.get_argument('password-c', None) disp_name = self.get_argument('disp-name', None) email = self.get_argument('email', None) if username is None or username == '': self.write( render_template('reg_error.html', error=lc.get('no_username'))) return if password is None or password == '': self.write( render_template('reg_error.html', error=lc.get('no_password'))) return if password != password_c: self.write( render_template('reg_error.html', error=lc.get('password_c_failed'))) return if disp_name is None or disp_name == '': self.write( render_template('reg_error.html', error=lc.get('no_disp_name'))) return if username in auth.get_user_list(): self.write( render_template('reg_error.html', error=lc.get('user_already_exists'))) return try: auth.register_user(username=username, password=password, disp_name=disp_name, email=email) except auth.BaseRegistrationError as e: self.write( render_template('reg_error.html', error=lc.get(e.text))) return self.redirect('/')
def register(): if request.method == 'POST': nickname = request.form.get('name', None) username = request.form.get('username', None) email = request.form.get('email', None) new_pass = request.form.get('new_pass', None) new_pass_again = request.form.get('new_pass_again', None) if nickname is None: flash('Please provide a name...', 'warning') if username is None: flash('Username is required', 'warning') if email is None: flash('Email is required') if new_pass is None or new_pass_again is None: flash("Password and password second time is required", 'warning') response = register_user(nickname, username, email, new_pass, new_pass_again) if response['error']: flash(response['error'], 'danger') else: flash( 'Successfuly register with provided information! You can now log in with username and password.', 'success') return redirect(url_for('login')) if session.get('user'): flash('Already logged in', 'info') flash('Please log out from current account before signup...', 'info') return redirect(url_for('index')) return render_template('auth/register.html', meta_title="Register")
def register(): data = json.loads(request.data) print(data) authentication = register_user(data['email'], data['password']) if authentication == None: return json.dumps({"status": "error"}) else: return json.dumps({"status": "success", "authtoken": authentication})
def register(): # Get parameters email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') # Generate hashed password hash = hashlib.sha256(password.encode()).hexdigest() # Connect to database connection = psycopg2.connect(user="******", password=os.environ.get("DATABASE_PASSWORD"), host="localhost", port="5432", database="twitterbrief") cursor = connection.cursor() if not auth.check_unique_credentials(username, email, cursor): return dumps({ "Error": "Credentials already exist!" }), 500 # Get followed user response = auth.get_followed_twitter_accounts(username) if response.status_code != 200: print(response.json()) return dumps({ "Error": "Invalid Twitter Account" }), 500 # Add user to database auth.register_user(username, email, hash, cursor) follows = response.json() # Add followed accounts auth.add_accounts(follows['ids'], cursor) auth.populate_followed_users(username, follows['ids'], cursor) # Close database connection connection.commit() cursor.close() connection.close() # Return token return auth.generate_token(username)
def register(): if authenticated() and (not has_role(['admin'])): return '请先注销当前登录' if request.method == 'GET': return render_template('register.html') else: registering_user = register_user(request.form['username'],request.form['password']) if registering_user is not None: if not 'user' in session: session.permanent = True session['user'] = {'username':registering_user.name, 'uid':registering_user.id, 'roles':[role.name for role in registering_user.roles]} return redirect('/user/home') elif has_role(['admin']): return redirect('/user/register') else: return redirect('/user/register')
def register(request): if request.user.is_authenticated: return HttpResponse('The User is already logged in... Cant register') if request.method == 'POST': # create a form instance and populate it with data from the request: form = RegisterForm(request.POST) # check whether it's valid: if form.is_valid(): get = form.cleaned_data.get if not auth.does_account_exist(get('email')): user = auth.register_user(get('firstname'), get('lastname'), get('email'), get("password")) #messages.success("A new user has been registered") return render(request, 'info.html', {'message': 'An email has been sent to your account please verify it'}) return render(request, 'oops.html', {'error_code': 100, 'message': 'account already exitst'}) else: return HttpResponse('Invalid form submitted') return HttpResponse('Invalid method for sensitive information')
def post(self): args = RequestParser(). \ add_body_argument('nickname', required=True). \ add_body_argument('phone', required=True, filter='\d{11}'). \ add_file_argument('headimg', type=HTTPFile). \ add_body_argument('sex', type=str, default='男'). \ add_body_argument('password', required=True, filter='[\w\[email protected]]{6,}'). \ add_body_argument('unique_id'). \ add_body_argument('code'). \ parse_args(self) user = yield register_user(password=args.password, nickname=args.nickname, code=args.code, headimg=args.headimg, sex=args.sex, phone=args.phone, unique_id=args.unique_id) self.write_success({ "user": user.to_json(), "token": AuthorizerHelper.generate_token(user) })
svc = in_json["svc"] if "svc" in in_json else "" auth_obj = {"status": 0} if svc != "search_objects_no_auth": auth_obj = auth.authenticate(mongo_cl_log) logged_email = auth_obj["email"] if auth_obj[ "status"] == 1 else "" if svc == "login_user": out_json = {} auth_obj = auth.login(mongo_cl_users, in_json, config_json["dbinfo"]["sessionlife"], mongo_cl_log) logged_email = auth_obj["email"] if auth_obj[ "status"] == 1 else "" elif svc == "register_user": out_json = auth.register_user(mongo_cl_users, in_json, mongo_cl_log) elif svc == "get_profile" and (auth_obj["status"] == 1 or local_flag): out_json = auth.get_profile(mongo_cl_users, auth_obj, config_json["profileinfo"], mongo_cl_log) elif svc == "save_profile" and (auth_obj["status"] == 1 or local_flag): out_json = auth.save_user(mongo_cl_users, in_json, logged_email, mongo_cl_log) elif svc == "reset_password" and (auth_obj["status"] == 1 or local_flag): current_pass, new_pass = in_json["passwordone"], in_json[ "passwordtwo"] out_json = auth.reset_password(mongo_cl_users, logged_email, current_pass, new_pass,
def register(): if request.method == 'POST': return auth.register_user(request) ### Display sign up form return render_template('signup.html')
def _post_api(path, query, session, *, send_json, send_error): if path == '/login': if 'username' not in query: return send_json({'error': 'No username'}) if 'password' not in query: return send_json({'error': 'No password'}) success, reason = check_login(query['username'], query['password']) if not success: return send_json({'error': reason}) session.activate_login(query['username'], query.get('handshake')) return send_json({'ok': reason}) elif path == '/register': if 'username' not in query: return send_json({'error': 'No username'}) if 'password' not in query: return send_json({'error': 'No password'}) success, reason = register_user(query['username'], query['password']) if not success: return send_json({'error': reason}) # also login session.activate_login(query['username'], query.get('handshake')) return send_json({'ok': reason}) elif path == '/post_message': if not session or not session.privileged: return send_json({'error': 'Not logged in with privileges'}) if 'message' not in query: return send_json({'error': 'No message'}) try: message = json.loads(query['message']) except: logger.warning('Message load threw a JSON err', exc_info=True) logger.info(f'Message was: {query["message"]}') return send_json({'error': 'Bad message format'}) message_keys = ['encrypted', 'message'] if not set(message_keys) <= set(message): return send_json({'error': 'Bad message format'}) rs = message.get('recipients', []) if not isinstance(rs, list): return send_json({'error': 'Bad message format'}) if len(rs) > 2: return send_json({'error': 'Too many recipients'}) for r in rs: if not check_username(r): return send_json({'error': 'Bad recipient username'}) if not check_user_exists(r): return send_json({'error': f'User {r} does not exist'}) message = {k: message[k] for k in message_keys} message['recipients'] = rs if message['encrypted']: message_bytes = bytes.fromhex(message['message']) message_bytes = encrypt_message(message_bytes, author=session.user, recipients=rs) message['message'] = message_bytes.hex() message['encrypted'] = bool(message['encrypted']) message['author'] = session.get('username') message['timestamp'] = time.time() token = save_message(message) return send_json({'ok': 'Message published', 'token': token}) elif path == '/set_status': if 'status' not in query: return send_json({'error': 'No status'}) if not session: return send_json({'error': 'Login first'}) if not session.set_persist('status', query['status']): return send_json({'error': 'Status write failed'}) return send_json({'ok': 'Status updated'}) else: return send_error(404, 'Not Found')
def post(self): with locks.global_lock: session_id = self.get_cookie('session_id') session = auth.load_session(session_id) if session is None or not session.is_admin: self.write( render_template('admin_error.html', error=lc.get('not_admin'))) return username = self.get_argument('username', None) password = self.get_argument('password', None) password_c = self.get_argument('password-c', None) disp_name = self.get_argument('disp-name', None) email = self.get_argument('email', None) is_admin = self.get_argument('is_admin', None) if is_admin is not None and is_admin not in ['on', 'off']: self.write( render_template( 'reg_error.html', error=lc.get('api_invalid_data_type').format( param='is_admin', expected=lc.get('bool'), ))) return if is_admin == 'on': is_admin = True else: is_admin = False if username is None or username == '': self.write( render_template('reg_error.html', error=lc.get('no_username'))) return if password is None or password == '': self.write( render_template('reg_error.html', error=lc.get('no_password'))) return if disp_name is None or disp_name == '': self.write( render_template('reg_error.html', error=lc.get('no_disp_name'))) return if password != password_c: self.write( render_template('reg_error.html', error=lc.get('password_c_failed'))) return if username in auth.get_user_list(): self.write( render_template('reg_error.html', error=lc.get('user_already_exists'))) return try: auth.register_user( username=username, password=password, disp_name=disp_name, email=email, is_admin=is_admin, ) except auth.BaseRegistrationError as e: self.write( render_template('reg_error.html', error=lc.get(e.text))) return self.redirect('/admin')