Esempio n. 1
0
    def test_user_cannot_register_with_wrong_email_format(self):
        email = "wrong_email_format"
        password = "******"
        username = "******"

        user = User(email, password, username)
        with self.assertRaises(UserError.InvalidEmail):
            user.register()
Esempio n. 2
0
def delete_friend(username):
    friend = User.find_by_username(username)
    friend.delete(username)
    user = User.find_by_username(session['username'])
    user.friends.remove(username)
    user.save_to_mongo()

    return redirect(url_for('.view_friends'))
Esempio n. 3
0
def index():
    friends = User.view_friends(session['username'])
    if friends:
        for friends in friends:
            user = User.find_by_username(friends.friend)
            seeds = Seed.find_by_user(user._id)

            return render_template('users/show_activities.html', seeds=seeds, user=user, standard=datetime.timedelta(0))
    return render_template('users/no_activities.html')
Esempio n. 4
0
def update_seeds():
    friends = User.view_friends(session['username'])
    seeds = []
    if friends:
        for friends in friends:
            user = User.find_by_username(friends.friend)
            seeds = [s.json() for s in Seed.find_updated_seeds(user._id)]

    return jsonify({'new_seeds': seeds})
Esempio n. 5
0
def search_friends_result():
    results = []
    user = User.find_by_username(session['username'])
    if request.method == 'POST':
        search_term = request.form['search']
        search_term = search_term.lower()
        if search_term != '':
            results = User.search_friend(search_term)

    return render_template('users/search_friends.html', results=results, user=user)
Esempio n. 6
0
    def test_user_cannot_log_in_with_invalid_username_or_password(self):

        email = "*****@*****.**"
        password = "******"
        username = "******"

        user = User(email, password, username)

        with self.assertRaises(UserError.InvalidLogin):
            user.login_valid()
Esempio n. 7
0
    def test_save_to_database(self):

        user = User("*****@*****.**", "abc123", "usertwo")
        user.save_to_database()

        job = Job("Server")
        job.save_to_database()

        user_job = UserJob(user, job)

        user_job.save_to_database()
Esempio n. 8
0
    def test_user_can_be_deleted_from_database(self):
        username = "******"
        email = "*****@*****.**"
        password = "******"

        user = User(email, password, username=username)
        user.register()

        User.delete(user)
        user = User.query.filter_by(email=email).first()
        self.assertIsNone(user)
Esempio n. 9
0
def register():
    form = RegistrationForm(request.form)
    users = User.query.all()
    if form.validate_on_submit():
        admin_status = check_admin_password(form.admin_password.data)
        try:
            user = User(form.email.data, form.password.data, form.employee_number.data, admin=admin_status)
            user.register()
            user.login()
            return redirect(url_for('.home'))
        except UserErrors.UserError as e:
            pass
    return render_template('auth/register.html', users=users, form=form)
Esempio n. 10
0
    def test_user_can_register(self):

        username = "******"
        email = "*****@*****.**"
        password = "******"

        user = User(email, password, username=username)
        user.register()
        user_from_db = User.query.filter_by(email=email).first()

        self.assertEqual(user_from_db.username, username)
        db.session.delete(user_from_db)
        db.session.commit()
Esempio n. 11
0
    def test_invalid_id_throws_error(self):

        email = "*****@*****.**"
        password = "******"
        username = "******"

        user = User(email, password, username)
        user.register()

        with self.assertRaises(UserError.InvalidUserId):
            User.get_user_by_id(-1)

        db.session.delete(user)
        db.session.commit()
Esempio n. 12
0
def user_register():
    if request.method == 'POST':
        username = request.form['username']
        username = username.lower()
        password = request.form['password']
        re_password = request.form['re-password']
        email = request.form['email']
        file = request.files['image']
        filename = ""

        if password == re_password:
            newpath = 'static/uploads'
            if not os.path.exists(newpath):
                os.makedirs(newpath)

            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)

                file.save(os.path.join(newpath, filename))
            if User.register_user(username, password, email, filename):
                session['username'] = username
                return redirect(url_for('.index'))
        else:
            raise UserError.RetypePassword("Please confirm the two fields of password are the same")
    return render_template('users/register.html')
Esempio n. 13
0
def edit_user(user_id):
    user = User.get_user_by_id(user_id)
    form = AdminUpdateUserForm(request.form)
    if user:
        return render_template('admin/update_user.html', form=form, user=user)

    return redirect(url_for('.user_list'))
Esempio n. 14
0
    def test_get_user_by_user_id(self):

        email = "*****@*****.**"
        password = "******"
        username = "******"

        user = User(email, password, username)
        user.register()

        user_object = User.get_user_by_id(user.id)

        self.assertEqual(email, user_object.email)
        self.assertEqual(password, user_object.password)

        db.session.delete(user_object)
        db.session.commit()
Esempio n. 15
0
    def test_user_can_log_in_to_session(self):

        email = "*****@*****.**"
        password = "******"
        username = "******"

        user = User(email, password, username)
        user.register()

        with app.test_client() as c:
            c.get("/")
            user.login()
            assert session["email"] == "*****@*****.**"

        db.session.delete(user)
        db.session.commit()
Esempio n. 16
0
def update_seed(seed_id):
    seed = Seed.find_by_id(seed_id)
    if request.method == 'POST':
        title = request.form['title']
        content = request.form['content']
        file = request.files['image']
        user = User.find_by_username(session['username'])
        user_id = user._id
        filename = ""

        newpath = 'static/uploads/' + session['username']
        if not os.path.exists(newpath):
            os.makedirs(newpath)

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(newpath, filename))
        if request.form.get('private'):
            _private = "private"
        else:
            _private = "public"

        seed.title = title
        seed.content = content
        seed.user_id = user_id
        seed.private = _private
        if filename:
            seed.image = filename
        seed.save_to_mongo()
        return redirect(url_for('.view_seeds'))
    return render_template('/seeds/update_seed.html', seed=seed)
Esempio n. 17
0
def update_user(username):
    user = User.find_by_username(username)
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        file = request.files['image']
        filename = ""

        newpath = 'static/uploads'
        if not os.path.exists(newpath):
            os.makedirs(newpath)

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)

            file.save(os.path.join(newpath, filename))

        user.username = username
        user.email = email
        if filename:
            user.image = filename
        user.save_to_mongo()
        session['username']=username
        return redirect(url_for('.index'))
    return render_template('users/update_user.html', user=user)
Esempio n. 18
0
 def __init__(self, user_id, start=None, end=None):
     self.user = User.get_user_by_id(user_id)
     self.start_date = start or beginning_of_week()
     self.end_date = end or end_of_week()
     self.shifts = Shift.get_shifts_by_user_id(user_id, start_time=start, end_time=end)
     self.row = [None] * self.get_count_of_days_in_range()
     self.populate_list_of_shifts()
Esempio n. 19
0
    def test_user_can_update_their_username(self):

        original_username = "******"
        original_email = "*****@*****.**"
        original_password = "******"

        user = User(original_email, original_password, username=original_username)
        user.register()

        new_username = "******"
        user.update(username=new_username)

        user = User.query.filter_by(email=original_email).first()
        self.assertNotEqual(user.username, original_username)

        db.session.delete(user)
        db.session.commit()
Esempio n. 20
0
    def test_user_can_update_their_password(self):

        original_username = "******"
        original_email = "*****@*****.**"
        original_password = "******"

        user = User(original_email, original_password, username=original_username)
        user.register()

        new_password = "******"
        user.update(password=new_password)

        user = User.query.filter_by(email=original_email).first()
        self.assertNotEqual(user.password, original_password)

        db.session.delete(user)
        db.session.commit()
Esempio n. 21
0
def user_login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        if User.is_valid_login(username, password):
            session['username'] = username
            return redirect(url_for('.index'))

    return render_template('users/login.html')
Esempio n. 22
0
def add_user():
    form = AddUserForm(request.form)
    users = User.query.all()
    if form.validate_on_submit():
        username = request.form['username']
        employee_number = request.form['employee_number']
        email = request.form['email']
        password = request.form['password']
        admin_password = request.form['admin_password']
        admin_status = check_admin_password(admin_password)
        user = User(employee_number=employee_number,
                    username=username,
                    email=email,
                    password=password,
                    admin=admin_status)
        user.save_to_database()
        return redirect(url_for('.user_list', users=users))

    return render_template('admin/add_user.html', users=users, form=form)
Esempio n. 23
0
def login_user():
    if request.method=='POST':
        email=request.form['email']
        password=request.form['password']
        try:
            if User.is_login_valid(email,password):
                session['email']=email
                return redirect(url_for('.user_alerts'))
        except UserErrors.UserError as e:
                return e.message

    return render_template("users/login.html")
Esempio n. 24
0
def login():
    form = LoginForm(request.form)
    users = User.query.all()
    if request.method == 'POST':
        try:
            user = User.get_user_by_employee_number(form.employee_number.data)
            user.login()
            return redirect(url_for('.home'))
        except UserErrors.UserError as e:
            return render_template('auth/login.html', users=users, form=form, site_title="Login")

    return render_template('auth/login.html', site_title="Login", users=users, form=form)
Esempio n. 25
0
 def decorated_function(*args, **kwargs):
     if 'email' not in session.keys() or session['email'] is None:
         return redirect(url_for('users.login', next=request.path))
     if session['email'] not in app.config['ADMINS']:
         return redirect(url_for('users.login'))
     if return_user:
         user = User.getByEmail(session['email'])
         return func(
             user, **
             kwargs)  #func(...) args: func(5, 6) kwargs: func(x=5, y=6)
     return func(
         *args,
         **kwargs)  # func(...) args: func(5, 6) kwargs: func(x=5, y=6)
Esempio n. 26
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for('.user_alerts'))
        except errors.UserErrors as e:
            return e.message

    return render_template("users/register.jinja2")
def register_user():
    if (request.method == ['POST']):
        email = request.form['email']
        password = request.form['hashed']
        print(email)
        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for('.user_alerts'))
        except UserErrors.UserError as e:
            return e.message

    return render_template('users/register.html')
Esempio n. 28
0
def login_user():
    if request.method == 'POST':
        # need user entered email and password for check
        email = request.form['email']
        password = request.form['hashed']
        #check if login is valid and if so create session
        if User.is_login_valid(email, password):
            # rememeber session is a temp storage. it has a unique id provided by us, so we know the session is associate with that email
            session['email'] = email
            # show user pages
            return redirect(url_for(".user_alerts"))
    # this is outside of the if to handle if there is GET request, show the user login
    return render_template("users/login.html")
Esempio n. 29
0
def login_user():  # Views form required for user login
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                ## CHANGE ##
                return redirect(url_for(".user_profile"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/login.jinja2")
Esempio n. 30
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['hashed']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("user/register.html")
Esempio n. 31
0
def login_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.login_valid(email, password):
                session['email'] = email
                return redirect(url_for(".user_sked"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("/users/login.html")
Esempio n. 32
0
def update_user():
    user_id = request.form['user_id']
    username = request.form['username']
    employee_number = request.form['employee_number']
    email = request.form['email']
    admin = True if request.form['admin'] == 'true' else False
    user = User.get_user_by_id(user_id)
    user.update(username=username,
                employee_number=employee_number,
                email=email,
                admin=admin)

    return redirect(url_for('.user_list'))
Esempio n. 33
0
def login_user():
    if request.method == "POST":
        email = request.form["email"]
        password = request.form["password"]

        try:
            if User.is_login_valid(email, password):
                session['email']=email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/login.html")
Esempio n. 34
0
def login_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.is_valid_login(email, password):
                session["email"] = email
                return redirect(url_for(".user_alerts"))
        except UserError.UserError as e:
            return e.message

    return render_template("users/login.j2")
Esempio n. 35
0
def user_login():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for(".user_alert"))
        except UserError.UserError as e:
            return e.message

    return render_template('/users/login.html')
Esempio n. 36
0
def register_user():
    if request.method == 'POST':
        # print(request.form)
        email = request.form.get('email')
        password = request.form.get('password')
        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message
    return render_template(
        "users/register.jinja2")  # wish to return a pop-up window
Esempio n. 37
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.jinja2")  # Send the user an error if their login was invalid
Esempio n. 38
0
def user_register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        re_password = request.form['re-password']
        if User.register_user(username, password):
            if re_password == password:
                session['username'] = username
                return redirect(url_for('home_page'))
            else:
                raise UserError.ReTypePasswordError("Please confirm re-type password is the same as password")

    return render_template('/users/register.html')
Esempio n. 39
0
def manage_lists():
    # This will handle displaying form and adding new list
    user = User.find_by_username(session['username'])

    if request.method == 'POST':
        new_list = request.form['newList']

        user.lists.append(new_list)
        user.update()

        return redirect(url_for('.manage_lists', lists=user.lists))

    return render_template('users/manage_lists.html', lists=user.lists)
Esempio n. 40
0
 def __init__(self,
              game,
              author,
              preview,
              created_on,
              updated_on=None,
              _id=None):
     self.game = Game.get_game_by_id(game)
     self.author = User.get_user_by_id(author)
     self.preview = preview
     self.created_on = created_on
     self.updated_on = updated_on
     self._id = uuid.uuid4().hex if _id is None else _id
Esempio n. 41
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.jinja2")  # could improve by sending user error if login invalid
Esempio n. 42
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.jinja2") # Send the user to the page if the login was invalid
Esempio n. 43
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for('.user_alerts'))
        except UserErrors.UserError as e:
            return e.message

    return render_template('users/register.html')
Esempio n. 44
0
def login_user():
    # don't pass the parameters because this a post method and not a get
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['hashed']

        try:
            if User.is_login_valid(email,password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message
        return render_template("users/login.html")
Esempio n. 45
0
def login_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for('.user_alerts'))  #url_for busca el archivo del metodo en el parametro .user_alerts --> el punto es porque es en est archivo
        except UserErrors.UserError as e:
            return e.message                # asi no tengo que hacer 2 excepts, uno para UserNotExistsError y otro para IncorrectPasswordError

    return render_template('users/login.html') #send the user an error if the login was invlid.
Esempio n. 46
0
def login_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for('.user_alerts'))
        except UserErrors.UserError as e:
            return e.message

    return render_template('users/login.html')  # send the user an error if their login was invalid
Esempio n. 47
0
def signup_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for("alerts.index"))
        except UserError as e:
            return e.message

    return render_template("users/signup.html")
Esempio n. 48
0
def add_reply(item_id):
    if session.get('email') is None:
        return render_template("login.jinja2",
                               message="You must be logged in to add items")
    else:
        if request.method == 'POST':

            # TODO: add check sender_id and recipient id to verify they are not same to avoind sending to oneself.
            content = request.form['content']
            message = Message.get_main_message_by_item_id(item_id)
            if message is not None:
                user = User.get_user_by_email(
                    collection=UserConstants.COLLECTION,
                    email=session['email'])
                if user._id == message.sender_id:
                    # TODO: verify none is none or empty.
                    new_message = Message(
                        title=message.title,
                        content=content,
                        item_id=item_id,
                        sender_id=user._id,
                        sender_username=user.username,
                        recipient_id=message.recipient_id,
                        recipient_username=message.recipient_username,
                        parent_id=message._id)
                    new_message.save_to_mongo()
                    return make_response(get_sent_messages(user.email))
                elif user._id == message.recipient_id:
                    new_message = Message(
                        title=message.title,
                        content=content,
                        item_id=item_id,
                        sender_id=user._id,
                        sender_username=user.username,
                        recipient_id=message.sender_id,
                        recipient_username=message.sender_username,
                        parent_id=message._id)
                    new_message.save_to_mongo()
                    return make_response(get_sent_messages(user.email))
                else:
                    return render_template(
                        "message_center.jinja2",
                        message=
                        "you are not allowed to view details of this message")
            else:
                return render_template(
                    "message_center.jinja2",
                    message="could not find message to reply to")
        else:
            return render_template("message_center.jinja2")
Esempio n. 49
0
def register_user():
    if request.method == 'POST':
        #check login is valid
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.html") # send the user an error if their login was invalid
Esempio n. 50
0
def login_user():
    if request.method == "POST":
        #Check Login is valid
        email = request.form['email']
        password = request.form['password']
        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for('.index'))
        except UserErrors.UserError as e:
            return e.message

    return render_template(
        "login.jinja2")  #Send the User an error is needed if login is invalid
def register_user():
    if request.method == "POST":
        email = request.form["email"]
        password = request.form["password"]

        try:
            if User.register_user(email, password):
                session["email"] = email
                return redirect(url_for(".user_alerts"))

        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.jinja2")
Esempio n. 52
0
def register_user():   # Views form required for user signup
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        fName = request.form['fName']
        age = request.form['age']
        try:
            if User.register_user(email, password, fName, age):
                session['email'] = email
                return redirect(url_for(".user_homepage"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.jinja2")
Esempio n. 53
0
def edit_preview(game_id):
    if request.method == 'POST':
        content = request.form['content']
        if Database.find_one(PreviewConstants.COLLECTION,
                             {"game": game_id, "author": User.get_user_by_email('*****@*****.**')._id}):
            preview = Preview.get_pops_preview_by_game(game_id)
            preview.preview = content
            preview.author = User.get_user_by_email('*****@*****.**')
            preview.updated_on = datetime.datetime.now()
            preview.save_to_mongo()
        else:
            preview = Preview(game_id, User.get_user_by_email('*****@*****.**')._id, content, datetime.datetime.now())
            preview.save_to_mongo()
        if 'saveandemail' in request.form:
            Preview.send(preview)
        return render_template("games/edit_preview.jinja2", preview=preview)
    else:
        if Database.find_one(PreviewConstants.COLLECTION,
                             {"game": game_id, "author": User.get_user_by_email('*****@*****.**')._id}):
            preview = Preview.get_pops_preview_by_game(game_id)
            return render_template("games/edit_preview.jinja2", preview=preview)
        else:
            return render_template("games/create_preview.jinja2")
Esempio n. 54
0
def register_user():
    # If a user does not exist, register it and then log it in
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']  # Hashed pw from user input form

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors as e:
            return e.message

    return render_template('users/register.jinja2')
Esempio n. 55
0
def login_user():
    if request.method == 'POST':
        # check if login is valid
        email = request.form['email']
        password = request.form['hashed']

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("user/login.html")
Esempio n. 56
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserError as e:
            return render_template("users/login_failed.html",
                                   message=e.message)  # TODO: change this

    return render_template("users/register.html")
Esempio n. 57
0
def login_user():
    if request.method == 'POST':
        email = request.form["email"]
        password = request.form["password"]
        try:
            if User.is_valid_login(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserError as e:
            return e.message

    return render_template(
        "users/login.jinja2"
    )  # send the user an error if their login was invalid.
Esempio n. 58
0
def login_user():
    # 两种不同的 methods 对应不同的动作
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']  # Hashed pw from user input form

        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors as e:
            return e.message

    return render_template("users/login.jinja2")
Esempio n. 59
0
def edit_alert(alert_id):
    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert = Alert.find_by_id(session['email'], alert_id)
        alert.price_limit = price_limit
        alert.load_item_price()
        user = User.find_by_email(session['email'])
        return render_template("users/alerts.jinja2",
                               alerts=user.get_alerts(),
                               user=user)

    return render_template("alerts/edit_alert.jinja2",
                           alert=Alert.find_by_id(session['email'], alert_id))
Esempio n. 60
0
    def test_user_login_is_valid(self):

        username = "******"
        email = "*****@*****.**"
        password = "******"

        user = User(email, password, username=username)
        user.register()

        self.assertTrue(user.login_valid())
        user.delete()