def main(): conn = init_db() try: conn.use(config.db_name) User(username='******', password='******', group=0) except r.errors.ReqlOpFailedError: build_db(conn) User(username='******', password='******', group=0) except ThinkTwiceException: pass init_routes() app.run(host=config.webapi_host, port=config.webapi_port) return 0
def sign_up_user_post(environ, start_response): """ Used to manage sign up user request. Manage sign_up.html request. Parameters ---------- start_response : start_response WSGI start_response environ : environ WSGI python environ Returns ------- list sign up view """ request = POST(environ) fields = set(field for field in User.__dict__) dct = {key: value for key, value in request.items() if key in fields} user = User(**dct) user.password = hashlib.sha256(user.password.encode()).hexdigest() try: Session = sessionmaker() Session.configure(bind=engine) session = Session() session.add(user) session.commit() return redirect(start_response, '/') except Exception as e: return redirect(start_response, '/')
def get_user(test_input): return User( _id=test_input["_id"], username=test_input["username"], firstname=test_input["firstname"], lastname=test_input["lastname"], email=test_input["email"], password=test_input["password"], created_at=test_input["created_at"], updated_at=test_input["updated_at"], permissions=test_input["permissions"], )
def register(): if current_user.is_authenticated : return redirect(url_for('home')) form=RegisterForm() if form.validate_on_submit() : hash_password=bcrypt.generate_password_hash(form.password.data).decode("utf-8") user=User(username=form.username.data,email=form.email.data,password=hash_password) db.session.add(user) db.session.commit() flash(f"'{form.username} is created you can login now ","success") return redirect(url_for('user.login')) return render_template("user/register.html",title="Register",form=form)
def test_user_legit_args(self, test_input, expected): user = User( username=test_input["username"], firstname=test_input["firstname"], lastname=test_input["lastname"], email=test_input["email"], password=test_input["password"], ) assert user.username == expected["username"] assert user.firstname == expected["firstname"] assert user.lastname == expected["lastname"] assert user.email == expected["email"] assert user.password == expected["password"]
def setUp(self): """ Prepares test case. Create an user call 'david'. """ password = hashlib.sha256('1t3st1t'.encode()).hexdigest() user = User(name='david', email='*****@*****.**', country='CO', password=password) Session = sessionmaker() Session.configure(bind=engine) session = Session() session.add(user) session.commit()
def test_unique_email(self): """ Verifies unique email. Tries to create user with email '*****@*****.**'. """ password = hashlib.sha256('1t3st1t'.encode()).hexdigest() user = User(name='jose', email='*****@*****.**', country='CO', password=password) with self.assertRaises(IntegrityError): Session = sessionmaker() Session.configure(bind=engine) session = Session() session.add(user) session.commit()
def signup(inputs): inputs["permissions"] = [] user = User(**inputs) if UserManager().insert_one(user): login_user(user) return user
def test_password_setter(self): u = User(password='******') self.assertTrue(u.password_hash is not None)
def test_no_password_getter(self): u = User(password='******') with self.assertRaises(AttributeError): u.password
def from_dict_to_object(data, state): username = data['username'] email = data['email'] client_id = data['client_id'] return User(username, email, client_id, state)
def put_user(request): try: User(request.json['username'], request.json['password']).export() return json({}) except ThinkTwiceException as e: return json({"error": e.message, "code": e.code}, status=e.code)