def addUser(user_name, email, password, confirm): user_added = False if len(user_name) == 0: flash("Please enter user name.") elif not EMAIL_REGEX.match( email): # test whether a field matches the pattern flash("Invalid email address.") elif not re.search(PWD_REGEX, password): flash( "Password must be 6-20 characters and contain one or more of each of: a number, uppercase letter, lower case letter, and special symbol." ) elif password != confirm: flash("Password confirmation does not match.") else: # check if email address already exists result = User.query.filter_by(email=email).first() if result: flash("Account already exists.") else: # add new member new_user = User(user_name=user_name, email=email, password=bcrypt.generate_password_hash(password), balance=starting_balance, current_game_id=None) db.session.add(new_user) db.session.commit() flash("New user added.") user_added = True return user_added
def index(): admin = User.query.filter_by(admin_status=1).all() if not admin: print("admin created") admin_pw_hash = bcrypt.generate_password_hash("admin") User.create_admin(admin_pw_hash) return render_template("login_registration.html")
def add_user(cls, user_data): hashed_pw = bcrypt.generate_password_hash(user_data["password"]) new_user = cls(first_name= user_data["first_name"], last_name= user_data["last_name"], email= user_data["email"], password= hashed_pw) db.session.add(new_user) db.session.commit() return new_user
def add_user(): if len(request.form['fname']) < 2: flash("First name is required") if len(request.form['lname']) < 2: flash("Last name is required") if not EMAIL_REGEX.match(request.form['email']): flash("Valid email is required") if len(request.form['address']) < 2: flash("Address is required") if len(request.form['city']) < 2: flash("City must be at least 2 characters") if len(request.form['state']) < 2: flash("State initials required, 2 characters") if len(request.form['password']) < 5: flash("password isn't long enough") if request.form['password'] != request.form['cpassword']: flash("password dont match") if '_flashes' not in session: new_user = User(first_name=request.form['fname'], last_name=request.form['lname'], email=request.form['email'], password_hash=bcrypt.generate_password_hash( request.form['password'])) db.session.add(new_user) db.session.commit() flash("Successfully added user") new_address = Address(user_id=new_user.id, address=request.form['address'], city=request.form['city'], state=request.form['state']) db.session.add(new_address) db.session.commit() flash("Address added") return redirect("/") return redirect('/')
def post(self): import string, random,datetime data = schema.load(request.get_json()) data.serial = ''.join(random.choices(string.ascii_lowercase + string.digits, k = serial_length)) data.date = datetime.datetime.now() #Handling the author stuff from schema.users import UserSchema authorData = User.find_by_uuid(get_jwt_identity()) data.author_id = authorData.id #encrypting posts, in the needed cases. if data.encryptionKey: data.status = 'encrypted' try: data.content = dataEnc.encodeString(data.content,data.encryptionKey) data.encryptionKey = bcrypt.generate_password_hash(data.encryptionKey) except Exception as e: log.error('Encryption error when creating a post! Check error message: {}'.format(e)) return {"message": "Internal server error!"},500 try: data.save_to_db() #save the post authorData.activity +=1 #increment the activity authorData.save_to_db() #save it return {"message": "Post created with serial `{}`.".format(data.serial)},201 except Exception as e: log.error('Database error when creating a new post. Check the error message: {}'.format(e)) return {"message":"Something went wrong. We can't upload this in our database."},500
def add_new_user(cls, user_data): karaoke_flag = False trivia_flag = False billiards_flag = False sunday_football_flag = False potluck_flag = False if 'karaoke' in user_data: karaoke_flag = True if 'trivia' in user_data: trivia_flag = True if 'billiards' in user_data: billiards_flag = True if 'sunday_football' in user_data: sunday_football_flag = True if 'potluck' in user_data: potluck_flag = True new_instance_of_user = cls(first_name=user_data['fname'], last_name=user_data['lname'], username=user_data['uname'], email=user_data['email'], password=bcrypt.generate_password_hash( user_data['password']), events_flag_karaoke=karaoke_flag, events_flag_trivia=trivia_flag, events_flag_billiards=billiards_flag, events_flag_football=sunday_football_flag, events_flag_potluck=potluck_flag) db.session.add(new_instance_of_user) db.session.commit() return new_instance_of_user
def register(): if current_user.is_authenticated: return redirect(url_for('listing')) form = RegistrationForm() if form.validate_on_submit(): existing_email = users.find_one({'email': form.email.data}) # Create new user only if email is not already in use if existing_email is None: hashed_password = bcrypt.generate_password_hash( form.password.data ).decode('utf-8') users.insert_one({ "username": form.username.data, "email": form.email.data, "password": hashed_password, }) # Log in once user is created in db user = users.find_one({'email': form.email.data}) login_user(User(user), remember=False) flash(f'Account created for {form.username.data}.', 'success') return redirect(url_for('listing')) else: flash(f'Something went wrong with the information provided.', 'danger') return render_template( 'pages/registration.html', title="Registration", form=form)
def add_new_user(cls, user_data): hashed_password = bcrypt.generate_password_hash(user_data["password"]) user_to_add = cls(name=user_data["name"], email=user_data["email"], password=hashed_password) db.session.add(user_to_add) db.session.commit() return user_to_add
def add_user(cls, data): password_hash = bcrypt.generate_password_hash(data["password"]) new_user = cls(username=data["username"], email=data["email"], password_hash=password_hash) db.session.add(new_user) db.session.commit() return new_user
def submitRegistration(): special_char = re.compile('[@_!#$%^&*()<>?/\|}{~:]') email_char = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') is_valid = True if len(request.form['first_name']) < 1: is_valid = False flash("Must enter first name") if len(request.form['last_name']) < 1: is_valid = False flash("Must enter last name") if len(request.form['pw']) < 5: is_valid = False flash("Password must be more than 5 characters") if special_char.search(request.form['pw']) == None: is_valid = False flash("Password must contain a special character") if any(char.isdigit() for char in request.form['pw']) == False: is_valid = False flash("Password must contain a number") if request.form['pw'] != request.form['c_pw']: is_valid = False flash("Passwords must match") if special_char.search(request.form['first_name']) != None: is_valid = False flash("First name cannot contain special characters") if special_char.search(request.form['last_name']) != None: is_valid = False flash("Last name cannot contain special characters") if any(char.isdigit() for char in request.form['first_name']) == True: is_valid = False flash("First name cannot contain a number") if any(char.isdigit() for char in request.form['last_name']) == True: is_valid = False flash("Last name cannot contain a number") if len(request.form['email']) < 1: is_valid = False flash("Must enter email") elif not email_char.match(request.form['email']): is_valid = False flash("Incorrect format for email") for user in users.query.all(): if request.form['email'] == user.email: is_valid = False flash("Email is already registered") if is_valid: pwd_hash = bcrypt.generate_password_hash(request.form["pw"]) newUser = users(first_name=request.form["first_name"], last_name=request.form["last_name"], email=request.form["email"], password=pwd_hash) db.session.add(newUser) db.session.commit() session["loggedInUserID"] = newUser.id return redirect('/resetHome') return redirect('/register')
def register_new(cls, form): hashed_pwd = bcrypt.generate_password_hash(form['password']) new_user = cls(first_name=form['first_name'], last_name=form['last_name'], email=form['email_address'], password=hashed_pwd) db.session.add(new_user) db.session.commit() return new_user.id
def add_new_user(cls, form): pw_hash = bcrypt.generate_password_hash(form['password']) new_user = cls(first_name=form['first_name'], last_name=form['last_name'], email=form['email'], password=pw_hash) db.session.add(new_user) db.session.commit() return new_user
def create(cls, form): pw_hash = bcrypt.generate_password_hash(form['password']) user = cls( username=form['username'], pw_hash=pw_hash, ) db.session.add(user) db.session.commit() return user.id
def new_user(cls, user_data): hashed_password = bcrypt.generate_password_hash(user_data['password']) user_to_add = cls(first_name=user_data['first_name'], last_name=user_data['last_name'], email=user_data['email'], password=hashed_password) db.session.add(user_to_add) db.session.commit() return user_to_add
def adduser(cls, data): pw_hash = bcrypt.generate_password_hash(data['password']) new_user = cls(first_name=data['fname'], last_name=data['lname'], email=data['email'], pw_hash=pw_hash) db.session.add(new_user) db.session.commit() return new_user
def create_user(cls, user_data): pw_hash = bcrypt.generate_password_hash( user_data['password']).decode("utf-8") create_user = cls(first_name=user_data["first_name"], last_name=user_data["last_name"], email=user_data["email"], password=pw_hash) db.session.add(create_user) db.session.commit() return create_user
def create(cls, form): print(f"PASS: {form['password']}") pw_hash = bcrypt.generate_password_hash(form['password']) user = cls(first_name=form['first_name'], last_name=form['last_name'], email=form['email'], password=pw_hash) db.session.add(user) db.session.commit() return user.id
def create_organization(cls, form): pw_hash = bcrypt.generate_password_hash(form['password']) organization = cls( email=form['email'], organization=form['organization'], password=pw_hash, ) db.session.add(organization) db.session.commit() return organization.id
def user_create(cls, form): pw_hash = bcrypt.generate_password_hash(form['password']) user = cls( first_name=form['first_name'], last_name=form['last_name'], email=form['email'], pw_hash=pw_hash, ) db.session.add(user) db.session.commit() return user.id
def register_user(cls, user_info): encrypted_pw = bcrypt.generate_password_hash(user_info['pass']) new_user = cls(name=user_info['name'], alias=user_info['alias'], email=user_info['email'], password=encrypted_pw) db.session.add(new_user) db.session.commit() for user in cls.query.all(): if user.email == new_user.email: session['userid'] = user.id
def add_new_user(cls, new_user_data): add_user = cls(first_name=new_user_data["first_name"], last_name=new_user_data["last_name"], email=new_user_data["email"], password=bcrypt.generate_password_hash( new_user_data["password"])) db.session.add(add_user) db.session.commit() flash( "User successfully added! Login to view the Quote Dash Dashboard!") return add_user
def add_new_customer(cls, new_customer_data): add_customer = cls(first_name=new_customer_data["first_name"], last_name=new_customer_data["last_name"], email=new_customer_data["email"], phone_number=new_customer_data["phone_number"], password=bcrypt.generate_password_hash( new_customer_data["password"])) db.session.add(add_customer) db.session.commit() flash("Registration successful! Log in to continue.") return add_customer
def add_new_user(cls, user_data): hashed_password = bcrypt.generate_password_hash(user_data['password']) new_user = cls(first_name=user_data['first_name'], last_name=user_data['last_name'], email=user_data['email'], passwordHash=hashed_password) db.session.add(new_user) print("adding new user...") print(new_user) db.session.commit() return new_user
def edit_user(cls, edit_user_data): edit_user = User.query.get(edit_user_data["login_id"]) edit_user.first_name = edit_user_data["first_name"] edit_user.last_name = edit_user_data["last_name"] edit_user.email = edit_user_data["email"] edit_user.date_of_birth = edit_user_data["birthday"] edit_user.phone_number = edit_user_data["phone_number"] edit_user.password = bcrypt.generate_password_hash( edit_user_data["password"]) db.session.commit() flash("User Information Updated") return edit_user
def register(): is_valid = validate_signup(request.form) if is_valid: pw_hash = bcrypt.generate_password_hash(request.form['password']) new_instance_of_user = User(user_name=request.form['user_name'], email=request.form['email'], location=request.form['location'], hashed_pw=pw_hash, birthdate=request.form['birthdate']) db.session.add(new_instance_of_user) db.session.commit() flash('Registered successfully!! Please sign in', 'success') else: flash('Unsuccessful. Please try again', 'errors') return redirect('/')
def update_user(cls, user_info): current_user = cls.query.get(int(session['userid'])) new_pass = bcrypt.generate_password_hash(user_info['password']) current_user.first_name = user_info['first_name'] current_user.last_name = user_info['last_name'] current_user.email = user_info['email'] current_user.street_address = user_info['address'] current_user.city = user_info['city'] current_user.state = user_info['state'] current_user.password = new_pass db.session.commit() flash("Account information has been updated!", "Success")
def register_user(): if not User.validate(request.form): return redirect("/") else: encrypted_pw = bcrypt.generate_password_hash(request.form['pw']) user = User(first_name=request.form['fn'], last_name=request.form['ln'], email=request.form['em'], password=encrypted_pw) db.session.add(user) db.session.commit() session['user_id'] = user.id return redirect("/tweets_landing")
def create_developer(cls, form): pw_hash = bcrypt.generate_password_hash(form['password']) developer = cls( first_name=form['first_name'], last_name=form['last_name'], email=form['email'], username=form['username'], password=pw_hash, ) db.session.add(developer) db.session.commit() return developer.id
def register(): errors = [] if len(request.form['first_name']) < 2: errors.append("First name must be at least 2 characters") valid = False if len(request.form['last_name']) < 2: errors.append("Last name must be at least 2 characters") valid = False if not EMAIL_REGEX.match(request.form['email']): errors.append("Email must be valid") valid = False if len(request.form['password']) < 8: errors.append("Password must be at least 8 characters") valid = False #TODO: Validate email is unique user_check = User.query.filter_by(email=request.form["email"]).first() if user_check is not None: errors.append("Email is in use") if request.form['password'] != request.form['confirm']: errors.append("Passwords must match") valid = False if errors: for e in errors: flash(e) else: hashed = bcrypt.generate_password_hash(request.form["password"]) new_user = None #TODO: Create New User file = request.files['pic'] filename = secure_filename(file.filename) filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(filepath) new_user = User( first_name = request.form["first_name"], last_name = request.form["last_name"], pic = filepath, email = request.form["email"], password = hashed ) db.session.add(new_user) db.session.commit() session["user_id"] = new_user.id return redirect("/products") return redirect("/")
def login_user(): user_info=User.validate_login(request.form) if user_info: session['MyWebsite_user_id']=user_info.id session['user_name']=user_info.first_name+" "+user_info.last_name session['login_session']=bcrypt.generate_password_hash(str(user_info.created_at)) session['email_address']=request.form['email_address'] if user_info.user_level==9: return redirect('/admin') else: return redirect('/user') flash("Login failed: email or password is incorrect",'login') return redirect('/signin')