def register_user(): if current_user.is_authenticated: flash('you are already logged-in') return redirect(url_for('pets.display_home')) # first time get request these values are set to none name = None email = None # create an instance of the RegisterForm. This function will get # passed to the decorator method route form = RegistrationForm() # if we get a post request (form has been submitted) then extract # the data from the form # if request.method == 'POST': # name = form.name.data # email = form.email.data # flask form method will validate the data with an implied post request # if POST and valid if form.validate_on_submit(): # capture the data a save in db User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash("Registration successful") # remember this is the post path so redirect to login page return redirect( url_for('authentication.do_the_login')) # blueprint url # else GET, return to reg form return render_template('registration.html', form=form)
def register_user(): if current_user.is_authenticated: #If user is already loggedin we shouldn`t show registration/login form flash('You are already logged in') return redirect(url_for('main.display_books')) form = RegistrationForm() #Method-1: #name = None #email = None #if request.method == 'POST': # name = form.name.data # email = form.email.data #return render_template('registration.html', form = form, name=name, email=email) #Method-2: (better way) if form.validate_on_submit( ): #This statement check if request is "POST", and also if data is valid User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration was succussful!') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
def register_user(): if current_user.is_authenticated: flash('you are already logged in') return redirect(url_for('main.home_page')) form = RegistrationForm() if form.validate_on_submit(): User.create_user(user=form.username.data, password=form.password.data) flash('Registration Successful') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
def register_user(): form = RegistrationForm() if form.validate_on_submit(): User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration Successful') return redirect(url_for('authentication.login_user')) return render_template('registration.html', form=form)
def register_user(): form = RegistrationForm() if current_user.is_authenticated: flash('you are already registered') return redirect(url_for('main.display_books')) if form.validate_on_submit(): User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration Successful') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
def register_user(): form = RegistrationForm() if form.validate_on_submit(): # rather than 'if request.method == 'POST':' User.create_user( user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration Successfull') return redirect(url_for('authentication.user_login')) return render_template('registration.html', form=form)
def register_user(): if current_user.is_authenticated: flash("You have already registered!") return redirect(url_for('main.display_books')) form = RegistrationForm() if form.validate_on_submit(): User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash("Registration Successful") return redirect(url_for("authentication.log_user_in")) return render_template("registration.html", form=form)
def test_login_incorrect(self): User.create_user(username='******', email='*****@*****.**', password=hash_password('cat')) incorrect_credential = { 'email': '*****@*****.**', 'password': '******', 'remember': 'y' } resp = self.client.post(url_for('auth.login'), data=incorrect_credential) self.assertEqual(resp.status_code, 200) self.assertIn('<h1>Login</h1>', resp.get_data(as_text=True))
def register_user(): form = RegistrationForm() if current_user.is_authenticated: flash("You're already logged in") return redirect(url_for('main.display_books')) if form.validate_on_submit( ): #check if method is POST and validate data in the form User.create_user(name=form.name.data, email=form.email.data, password=form.password.data) flash('Registration is successful!') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
def register_user(): if current_user.is_authenticated: flash('Already Logged In') return redirect(url_for('main.display_books')) form=RegistrationForm() if form.validate_on_submit(): User.create_user( user=form.name.data, email=form.email.data, password=form.password.data ) flash('User account created for'+form.name.data,'success') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
def test_login_correct(self): User.create_user(username='******', email='*****@*****.**', password=hash_password('cat')) correct_credential = { 'email': '*****@*****.**', 'password': '******', 'remember': 'y' } resp = self.client.post(url_for('auth.login'), data=correct_credential) self.assertEqual(resp.status_code, 302) self.assertIn('<a href="/test-view">/test-view</a>', resp.get_data(as_text=True))
def test_login_correct_follow(self): User.create_user(username='******', email='*****@*****.**', password=hash_password('cat')) correct_credential = { 'email': '*****@*****.**', 'password': '******', 'remember': 'y' } resp = self.client.post(url_for('auth.login'), data=correct_credential, follow_redirects=True) self.assertEqual(resp.status_code, 200) self.assertIn('login_pass', resp.get_data(as_text=True))
def _add_user_to_db(form): if form.validate(): user = User.create_user(form.username.data, form.password.data) login_user(user) return True return False
def register_user(): if current_user.user_cat != 'Adm': return redirect(url_for('authentication.acesso_negado')) form = RegistrationForm() if form.validate_on_submit(): User.create_user(user=form.nome.data, email=form.email.data, nivel=form.nivel.data, password=form.password.data) flash(f' Usuário {form.nome.data} registrado com sucesso') return redirect(url_for('authentication.do_the_login')) return render_template('insere_usuario.html', form=form)
def register_user(): if current_user.is_authenticated: flash('You are already logged in.') return redirect(url_for('authentication.homepage')) form = RegistrationForm() if form.validate_on_submit(): User.create_user( user=form.name.data, email=form.email.data, password=form.password.data ) flash("Registration Successful") return redirect(url_for('authentication.log_in_user')) return render_template('registration.html', form=form)
def register_user(): if current_user.is_authenticated: flash("You are already LoggedIn") return redirect(url_for('home_app.home')) form = RegistrationForm() if form.validate_on_submit(): User.create_user( user=form.username.data, email=form.email_id.data, password=form.password.data, ) flash("Registration Successfull","sucess") return redirect(url_for("authentication.do_the_login")) return render_template("authentication/registration.html", form=form)
def register_user(): form = RegistrationForm() if current_user.is_authenticated: flash('you are already registered') return redirect(url_for('main.display_books')) if form.validate_on_submit( ): # checks if form is a post request and checks if data is valid # these are arguments we have defined in the class method to store user data in the DB # form.name.data and the rest come from our form.py User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration Successful' ) # # flashes a message that says they are registered return redirect(url_for('authentication.do_the_login') ) # redirect to a login page after they are successful return render_template( 'registration.html', form=form ) # if not unsuccessful send back to registration page- This is a get request as opposed to a post request
def register_user(): if current_user.is_authenticated: flash('you are already logged in') return redirect(url_for('main.display_books')) form = RegistrationForm() if form.validate_on_submit(): # POST request, and validates data User.create_user( # capture data user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration successful') # flashes a temporary message return redirect( url_for('authentication.do_the_login') ) # sends User to login page as soon as registation is successful return render_template('registration.html', form=form) # Only served if it is a GET request
def user_registerAdmin(): """Register user.""" try: # Extract data from request. data_dict = get_data() name = data_dict['name'] email = data_dict['email'] password = data_dict['password'] # Create user in db. User.create_user(user=name, email=email, password=password, is_admin=True) # Registration was success. return {"result": True, "message": "Registration successfull."} except Exception as exc: traceback.print_exc() return {"result": False, "message": str(exc)}
def register_user(): if current_user.is_authenticated: flash('你已經登入') return redirect(url_for('authentication.homepage')) form = RegistrationForm(request.form) if request.method == 'POST' and form.validate_on_submit(): User.create_user(u_s_id=form.s_id.data, u_name=form.name.data, u_major=form.major.data, u_mail=form.s_id.data + '@nccu.edu.tw', u_state='正常', u_use_count=0, u_foul_count=0, u_password=form.password.data) flash("註冊成功") return redirect(url_for('authentication.log_in_user')) return render_template('registration.html', form=form)
def register_user(): # name = None # email = None # form = RegistrationForm() # if request.method == 'POST': # name = form.name.data # email = form.email.data # return render_template('registration.html', form=form, name=name, email=email) if current_user.is_authenticated: flash('You are already registered') return redirect(url_for('main.display_books')) form = RegistrationForm() if form.validate_on_submit( ): # ANALOGUE TO if request.method == 'POST': check if is a POST method and validate data User.create_user(user=form.name.data, email=form.email.data, password=form.password.data) flash('Registration Successful') return redirect(url_for('authentication.do_the_login')) return render_template('registration.html', form=form)
def signup(): message=None if request.method=='POST': req=request.form name=req['name'] email=req['email'] password=req['password'] user=User.query.filter_by(user_email=email).first() if user is None: User.create_user(user=name,email=email,password=password) user=User.query.filter_by(user_email=req['email']).first() if user.user_name is None: return redirect('/login') else: if bcrypt.check_password_hash(user.user_password,request.form['password']): session['email']=user.user_email session['name']=user.user_name return redirect('/profile') else: return render_template('sign_up.html',message='email id already exists') return render_template('sign_up.html')
def register_user(): form = RegistrationForm() if form.validate_on_submit(): # generate token and send to user to activate account activation_token = send_activation_email(form.email.data, form.first.data) User.create_user(first=form.first.data, last=form.last.data, email=form.email.data, activation=activation_token, username=form.username.data, password=form.password.data) if current_app.config['ACCOUNT_ACTIVATION']: flash( 'Registration successful, check your email to activate account' ) else: flash('Registration successful') return redirect(url_for('authentication.sign_in_user')) return render_template('registration.html', form=form, landing=True)
def register_user(): if not session['user_is_admin']: return redirect(url_for('authentication.unauthorized')) form = RegistrationForm() if form.validate_on_submit(): if User.query.filter_by(user_email=form.email.data).first(): flash('Email already exists.') else: user = User.create_user(form.first_name.data, form.last_name.data, form.email.data) flash(f'{user.user_email} successfully created.', category='success') return render_template('auth/registration.html', form=form)
def _log_in_as(self, user): roles = user.get('roles') or [] email, password = user['email'], user['password'] user = User.query.filter_by(email=email).first() if user is None: user = User.create_user(username=email, email=email, password=hash_password(password)) for role in roles: self._add_role_name_to_user(user, role) resp = self.client.post( url_for('auth.login'), data={ 'email': email, 'password': password, 'remember': 'y' # Not sure why it's required, but some # test cases having follow_redirects=True # fails without it. }) self.assertEqual(resp.status_code, 302)
def signup(): # Check if logged in, and redirect to home page in such case if 'user_id' in session: return redirect(url_for('home')) form = SignupForm() if request.method == "POST": if form.validate() == False: # reload the signup.html page if any validation check fails return render_template('signup.html', form=form) else: # message = User.create_user(username=username, email=email, password=password, confirm_passowrd=confirm_password) details = User.create_user(form.username.data, form.email.data, form.password.data, form.confirm_passowrd.data) # after a new user signs up, a new session is created. session['user_id'] = details[1].id return redirect(url_for('home')) elif request.method == "GET": return render_template('signup.html', form=form) '''
from app import create_app, db # app/__init__ (ROOT PACKAGE) from app.auth.models import User from sqlalchemy import exc flask_app = create_app('prod') with flask_app.app_context(): db.create_all() try: if not User.query.filter_by(user_name='harry').first(): User.create_user(user='******', email='*****@*****.**', password='******') except exc.IntegrityError: flask_app.run() except exc.NoSuchModuleError: flask_app.run()
from app import create_app, db from app.auth.models import User from sqlalchemy import exc # We can now simply pass whatever version of the app we wish to run into the function flask_app = create_app("dev") with flask_app.app_context(): db.create_all() try: if not User.query.filter_by(user_name="harry").first(): User.create_user(user='******', email='*****@*****.**', password='******') except exc.IntegrityError: flask_app.run()
random_int = seed_data.random_int(min=0, max=(len(url_data) - 1)) url = url_data[random_int] # add login time to some users so they appear online if seed_data.boolean(chance_of_getting_true=50): login_time = datetime.now() else: login_time = None user = User.create_user(first=seed_data.first_name(), last=seed_data.last_name(), email=email, activation=None, username=username, password='******', gender=gender, age=seed_data.random_int(min=18, max=40), preference=preference, position=position, lat=lat, lng=lng, biography=seed_data.text(max_nb_chars=200), login_time=login_time) Picture.add_pic(uid=user.id, url=url, profile_picture=True) random_int = seed_data.random_int(min=0, max=(len(tag_data) - 1)) tag = tag_data[random_int] Tag.add_tag(tag_uid=user.id, tag=tag) # add admin account
from app import create_app, db from app.auth.models import User from app.game.models import Game import sys if __name__ == '__main__': char_app = create_app('dev') with char_app.app_context(): db.create_all() user = User.query.filter_by(user_name='su_ironarmchad').first() if not user: user = User.create_user(user='******', password='******', role='SUPER') if not Game.query.filter_by(name='No Game').first(): Game.create_game(game_name='No Game', game_lore='', game_summary="", st_id=user.id) char_app.run() else: char_app = create_app('prod') with char_app.app_context(): db.create_all() user = User.query.filter_by(user_name='su_ironarmchad').first() if not user: user = User.create_user(user='******', password='******', role='SUPER')