def createUser(): u = User() u.user_id = 20 u.username = "******" u.password = "******" # u.save(force_insert=True) return u
async def create_user(request: Request, user: User = Body(...)): user.id = uuid.uuid4() # instantiate a unique UUID user.dateCreated = datetime.datetime.now() # instantiate the current date # Check if the username already exists if (existing_user := await request.app.mongodb['users'].find_one({"username": user.username} )) is not None: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"Username {user.username} already exists")
def user_create(): #Create a new user user_data = User_schema.load(request.json) new_user = User() new_user.user_email = user_data["user_email"] new_user.user_encrypted_password = user_data["user_encrypted_password"] db.session.add(new_user) db.session.commit() return jsonify(User_schema.dump(new_user)) # sql = "INSERT INTO books (title) VALUES (%s);" # cursor.execute(sql, (request.json["title"],)) # connection.commit() # sql = "SELECT * FROM books ORDER BY ID DESC LIMIT 1" # cursor.execute(sql) # book = cursor.fetchone() # return jsonify(book) # @users.route("/books/<int:id>", methods=["GET"]) # def book_show(id): # #Return a single book # sql = "SELECT * FROM books WHERE id = %s;" # cursor.execute(sql, (id,)) # book = cursor.fetchone() # return jsonify(book) # @users.route("/books/<int:id>", methods=["PUT", "PATCH"]) # def book_update(id): # #Update a book # sql = "UPDATE books SET title = %s WHERE id = %s;" # cursor.execute(sql, (request.json["title"], id)) # connection.commit() # sql = "SELECT * FROM books WHERE id = %s" # cursor.execute(sql, (id,)) # book = cursor.fetchone() # return jsonify(book) # @users.route("/books/<int:id>", methods=["DELETE"]) # def book_delete(id): # sql = "SELECT * FROM books WHERE id = %s;" # cursor.execute(sql, (id,)) # book = cursor.fetchone() # if book: # sql = "DELETE FROM books WHERE id = %s;" # cursor.execute(sql, (id,)) # connection.commit() # return jsonify(book)
def register(): if request.method == 'GET': session.clear() return render_template('register.html') # get the data from our form password = request.form['password'] conf_password = request.form['confirm-password'] username = request.form['username'] email = request.form['email'] role = request.form['role'] # make sure the password match if conf_password != password: flash("Passwords do not match") return render_template('register.html') # check if it meets the right complexity check_password = password_check(password) # generate error messages if it doesnt pass if True in check_password.values(): for k, v in check_password.items(): if str(v) == "True": flash(k) return render_template('register.html') # hash the password for storage pw_hash = bcrypt.generate_password_hash(password) # create a user, and check if its unique user = User(username, pw_hash, email, role) u_unique = user.unique() # add the user if u_unique == 0: db.session.add(user) db.session.commit() flash("Account Created") return redirect(url_for('login')) # else error check what the problem is elif u_unique == -1: flash("Email address already in use.") return render_template('register.html') elif u_unique == -2: flash("Username already in use.") return render_template('register.html') else: flash("Username and Email already in use.") return render_template('register.html')
def validateUser(username, password): u = User().getUserbyUsername(username) if not u: return False else: if (u.password == password): u.setAuthenticate() # ------------------------------------------------------------------------------ # Create New Session newController = Controller() newController.setUserId(u.user_id) newController.CreateController() sessionManager.createNewSession(u, newController) return True else: return False
def add_church(): if request.method == 'POST': church_name = request.form['church_name'] church_leader = request.form['church_leader'] church_email = request.form['church_email'] church_password = request.form['church_password'] message = '''Hello {} , we hope your the Leader of {} Church you have been requested to join Mychurch community here are log in credential \n\n Username :{} default-password:{} \n\n Please confirm this email in 24 hours'''.format( church_leader, church_name, church_name, church_password) token = s.dumps(church_email, salt='email-confirm') link = url_for('confirm', token=token, _external=True) msg = Message('Mychurch Email confirm', sender='*****@*****.**', recipients=[church_email]) msg.body = "{}\n\n{}".format(message, link) mail.send(msg) username = church_name email = church_email pw_hash = bcrypt.generate_password_hash(password=church_password) user = User(username, pw_hash, email) u_unique = user.unique() # add the user if u_unique == 0: db.session.add(user) db.session.commit() flash("The Church have been added") redirect('/add_church') elif u_unique == -1: flash("Church Email address exist.") redirect('/add_church') elif u_unique == -2: flash("Church name already exist.") redirect('/add_church') else: flash("Church name and Email already in use.") redirect('/add_church') return render_template('add_church.html', user=current_user)
def register(): if request.method == 'GET': session.clear() return render_template('register.html') # get the data from our form password = request.form['password'] conf_password = request.form['confirm-password'] username = request.form['username'] email = request.form['email'] # hash the password for storage n = 0 if conf_password != password: flash("Passwords do not match") n = 4 if n > 0: return render_template('register.html') # create a user, and check if its unique if n == 0: pw_hash = bcrypt.generate_password_hash(password) user = User(username, pw_hash, email) u_unique = user.unique() # add the user if u_unique == 0: db.session.add(user) db.session.commit() flash("Account Created") return redirect(url_for('login')) # else error check what the problem is elif u_unique == -1: flash("Email address already in use.") return render_template('register.html') elif u_unique == -2: flash("Username already in use.") return render_template('register.html') else: flash("Username and Email already in use.") return render_template('register.html')
def register(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] user = User(email=email, password=password) RequestsApi.get_register(user) return redirect(url_for('index')) elif request.method == 'GET': return render_template('/layouts/register.html')
def nuevousuario(): # get the data from the new user form password = request.form['password'] username = request.form['username'] email = request.form['email'] nombre = request.form['nombre'] apellido = request.form['apellido'] domiciliopart = request.form['domiciliopart'] telefonofijo = '' telefonocelular = request.form['telefonocelular'] localidad = request.form['localidad'] dni = request.form['dni'] provincia = request.form['provincia'] # hash the password for storage pw_hash = bcrypt.generate_password_hash(password) # create a user, and check if its unique user = User(username, pw_hash, email, nombre, apellido, domiciliopart, telefonofijo, telefonocelular, localidad, dni, provincia) u_unique = user.unique() # add the user if u_unique == 0: db.session.add(user) db.session.commit() return '200' # else error check what the problem is elif u_unique == -1: flash("Email existente.") return '502' elif u_unique == -2: flash("Usuario existente.") return '502' else: flash("Usuario y Email ya registrado.") return '502'
def login(): try: email = request.form['email'] password = request.form['password'] user = User(email=email, password=password) res = RequestsApi.get_login(user) session['login'] = True session['username'] = res['res']['data']['key'] return redirect(url_for('listed_by_user', user=session['username'])) except: return "Enter a valid username and password"
def add_user(): # check if the data is json if request.is_json: data = request.get_json(force=True) username = data['username'] email = data['email'] password = data['password'] # hashing the password harshed_password = bcrypt.generate_password_hash(password).decode( 'utf-8') #check if user exist if User.check_username(username): return jsonify({'message': 'Username already exists'}), 409 if User.check_email(email): return jsonify({'message': 'Email already exists'}), 409 addUser = User(username=username, email=email, password=harshed_password) try: record = addUser.insert_record() # creating an acess token to enable a user access a resource access_token = create_access_token(identity=record.id) # to renew an access token refresh_token = create_refresh_token(identity=record.id) return jsonify({ 'acess_token': access_token, "refresh_token": refresh_token }), 200 # return user_schema.jsonify(record),200 except Exception as e: return jsonify({'message': 'Error adding user'}), 500 else: jsonify({'message': 'JSON request expected'}), 400
def login_user(): # check if the data is json if request.is_json: data = request.get_json(force=True) username = data['username'] password = data['password'] # first chech if the user exist || if true check if the password check is correct if User.check_username(username=username): if User.check_password(username, password): user = User.fetch_by_username(username=username) access = create_access_token(identity=user.id) refresh_token = create_refresh_token(identity=user.id) return jsonify({ 'acess_token': access, "refresh_token": refresh_token }) else: return jsonify({'message': 'Invalid password'}), 401 else: return jsonify({'message': 'User not recognised'}), 401
def register(): if request.method == "GET": return render_template("register.html") else: username = request.form['username'] for ch in username: if not (ch.isalpha() or ch.isdigit()): flash("Invalid Username!") return redirect(url_for('register')) if User.query.filter_by(username=username).first(): flash("Username already taken, sorry!") return redirect(url_for('register')) else: password = request.form['password'] hashed_password = sha256_crypt.hash(password) email = request.form['email'] phone_no = request.form['phone_no'] if len(phone_no) > 12: flash("Invalid Phone no!") return redirect(url_for('register')) for ch in phone_no: if not ch.isdigit(): flash("Invalid Phone no!") return redirect(url_for('register')) bio = request.form['bio'] dob = request.form['dob'] try: valid_date = time.strptime(dob, '%Y-%m-%d') except ValueError: flash("Invalid Date of Birth!") return redirect(url_for('register')) fav_topics = request.form['fav_topics'] user = User(username=username, password=hashed_password, email=email, phone_no=phone_no, bio=bio, dob=dob) db.session.add(user) db.session.commit() db.session.close() flash("Successfully registered!") return redirect(url_for('homepage'))
def generate_token(request): form = MagicLink(request.form) if form.validate(): email = form.email.data user = User.query.filter_by(email=email).first() if user is None: """if the user doesn't exist already add him to the users table""" user = User(None, email, None) db.session.add(user) auth_token = AuthToken(user) if bot is not None: bot.api.messages.create( toPersonEmail=email, text='Please click on the following link to login: '******'?token=' + str(auth_token.token)) else: abort(500) db.session.add(auth_token) db.session.commit() return render_template('admin/thank_you.html') else: return render_template('admin/token.html', form=form)
def register_user(request): signup_form = SignupForm(request.form) if request.method == 'POST': if signup_form.validate(): name = request.form.get('name') email = request.form.get('email') password = request.form.get('password') existing_user = User.query.filter_by(email=email).first() if existing_user is None: user = User(name=name, email=email, password=password) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('home.show')) flash('A user already exists with that email address') return redirect(url_for('home.signup')) return render_template('admin/signup.html', form=signup_form)
def professor(): return User("professor", "Master Yoda")
def register(): if request.method == 'GET': session.clear() return render_template('register.html') # get the data from our form password = request.form['password'] conf_password = request.form['confirm-password'] username = request.form['username'] email = request.form['email'] nombre = '' apellido = '' domiciliopart = '' telefonofijo = '' telefonocelular = '' localidad = '' dni = '' provincia = '' # make sure the password match if conf_password != password: flash("La Contraseña no coincide") return render_template('register.html') # check if it meets the right complexity check_password = password_check(password) # generate error messages if it doesnt pass if True in check_password.values(): for k, v in check_password.items(): if str(v) == "True": flash(k) return render_template('register.html') # hash the password for storage pw_hash = bcrypt.generate_password_hash(password) # create a user, and check if its unique user = User(username, pw_hash, email, nombre, apellido, domiciliopart, telefonofijo, telefonocelular, localidad, dni, provincia) u_unique = user.unique() # add the user if u_unique == 0: db.session.add(user) db.session.commit() flash("Cuenta Creada") html = render_template( 'msgregistro.html', nombre=nombre, username=username) asunto = 'Crecion de cuenta en HRB BINGO VIRTUAL' enviarEmail('Su cuenta en HRB VINGO VIRTUAL', html, asunto, email) # sleep(2) return redirect(url_for('login')) # else error check what the problem is elif u_unique == -1: flash("Email existente.") return render_template('register.html') elif u_unique == -2: flash("Usuario existente.") return render_template('register.html') else: flash("Usuario y Email ya registrado.") return render_template('register.html')
def teachers_assistant(): return User("teachers_assistant", "Obi-Wan Kenobi")
def student(): return User("student", "Luke Skywalker")
def fetch_task(): # getting user id uid = get_jwt_identity() user = User.fetch_by_id(id=uid) return tasks_schema.jsonify(user.tasks), 200
def register(): if request.method == 'GET': session.clear() return render_template('register.html') # get the data from our form password = request.form['password'] conf_password = request.form['confirm-password'] username = request.form['username'] email = request.form['email'] algorythm = request.form['algorythm'] #make sure the algorythm is choosen if algorythm == 'Choose an algorythm:': flash('Algorythm is not choosen!') return render_template('register.html') # make sure the password match if conf_password != password: flash("Passwords do not match") return render_template('register.html') # check if it meets the right complexity check_password = password_check(password) # print(check_password, check_password.values()) # generate error messages if it doesnt pass if True in check_password.values(): for k in check_password: if str(check_password[k]) is "True": flash(k) return render_template('register.html') # public key from private key of username and password concat if algorythm == 'ECDSA': publicKey = createPublicKeyECDSA(username, password) # create a user, and check if its unique user = User(username, publicKey, email) u_unique = user.unique() # add the user if u_unique == 0: db.session.add(user) db.session.commit() flash("Account Created") return redirect(url_for('login')) # else error check what the problem is elif u_unique == -1: flash("Email address already in use.") return render_template('register.html') elif u_unique == -2: flash("Username already in use.") return render_template('register.html') else: flash("Username and Email already in use.") return render_template('register.html')