예제 #1
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect(url_for('homepage'))

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        if User.authenticate(g.user.username, form.password.data):
            g.user.username = form.username.data
            g.user.email = form.email.data
            g.user.image_url = form.image_url.data
            g.user.header_image_url = form.header_image_url.data
            g.user.bio = form.bio.data
            g.user.location = form.location.data

            db.session.add(g.user)
            db.session.commit()

            flash(f"{g.user.username} successfully edited")
            return redirect(url_for('homepage'))
        else:
            flash("Incorrect Password", "danger")
            return render_template("/users/edit.html",
                                   form=form,
                                   user_id=g.user.id)
    else:
        return render_template("/users/edit.html",
                               form=form,
                               user_id=g.user.id)
예제 #2
0
파일: app.py 프로젝트: westred22/warbler
def edit_profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    user = g.user
    form = UserEditForm(obj=user)

    if form.validate_on_submit():
        if User.authenticate(user.username, form.password.data):
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data or "/static/images/default-pic.png"
            user.header_image_url = form.header_image_url.data or "/static/images/warbler-hero.jpg"
            user.bio = form.bio.data

            user.location = form.location.data
            db.session.commit()
            return redirect(f"/users/{user.id}")

        flash("Wrong password, please try again.", 'danger')

    return render_template('users/edit.html', form=form, user_id=user.id)
예제 #3
0
def profile():
    """Update profile for current user."""

    # if not same user, deny access
    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():

        user = User.authenticate(g.user.username, form.password.data)

        if user:
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data
            db.session.commit()
            return redirect(f'/users/{g.user.id}')
        else:
            flash("Invalid credentials.", 'danger')
            return redirect("/")

    return render_template('users/edit.html', form=form)
예제 #4
0
def profile():
    """Update profile for current user."""

    form = UserEditForm(obj=g.user)
    user = User.query.get(g.user.id)
    if form.validate_on_submit():
        if User.authenticate(user.username, form.password.data):
            edit_attrs = {
                'email':
                form.email.data,
                'username':
                form.username.data,
                'image_url':
                form.image_url.data or User.image_url.default.arg,
                'header_image_url':
                form.header_image_url.data
                or User.header_image_url.default.arg,
                'bio':
                form.bio.data,
            }
            g.user.edit_profile(**edit_attrs)
            db.session.commit()
            flash("Profile edited!", "success")
            return redirect(url_for('users_show', user_id=user.id))
        else:
            flash("Invalid password", "danger")
            return redirect(url_for('homepage'))
    else:
        return render_template('users/edit.html', form=form, user=g.user)
예제 #5
0
파일: app.py 프로젝트: rayjc/newsmart
def user_profile_view():
    """
    User profile page:
        -Shows user information
        -form for updating user info; could consider patch request via ajax
        -list of articles user has saved/bookmarked with keywords extracted
        (These article keywords are used for recommendation)
    """
    form = UserEditForm(username=g.user.username)

    if form.validate_on_submit():
        user = User.update(g.user.username, form.username.data,
                           form.password.data)
        if user:
            flash("Username updated.", "success")
        return redirect(url_for('user_profile_view'))

    bookmarks = g.user.articles
    categories = Category.query.all()
    bookmark_map = newsmart.get_bookmark_url_to_id()

    return render_template(
        "user_profile.html",
        form=form,
        submit_button="Update User",
        bookmarks=bookmarks,
        bookmark_map=bookmark_map,
        category_objs=categories,
        categories=NEWS_CATEGORIES,
    )
예제 #6
0
파일: app.py 프로젝트: prkshadhkr/news
def signup():
    """Handle user signup.

    Create new user and add to DB. Redirect to home page.

    If form not valid, present form.

    If there already is a user with that username: flash message
    and re-present form.
    """
    if CURR_USER_KEY in session:
        del session[CURR_USER_KEY]
    form = UserEditForm()

    if form.validate_on_submit():
        try:
            user = User.signup(username=form.username.data,
                               password=form.password.data,
                               email=form.email.data,
                               country=form.country.data
                               or User.country.default.arg)
            db.session.commit()

        except IntegrityError as e:
            flash("Username already taken", 'danger')
            return render_template('users/signup.html', form=form)

        do_login(user)

        return redirect("/headlines")

    else:
        return render_template('users/signup.html', form=form)
예제 #7
0
def home():
    user_edit_form = UserEditForm(request.form)
    if request.method == 'POST' and user_edit_form.validate():
        user = User.query.filter_by(nickname=current_user.nickname).first()
        user.phone = user_edit_form.phone.data
        user.phone_verified = 1
        user.about = user_edit_form.about_me.data
        user.last_appointment = user_edit_form.last_appointment.data
        user.weight = user_edit_form.weight.data
        user.height = user_edit_form.height.data
        user.medical_history = user_edit_form.medical_history.data
        db.session.commit()
    user = User.query.filter_by(nickname=current_user.nickname).first()
    alert_dentist = False
    alert_physical = False
    if user.last_appointment:
        l_a = datetime.datetime.strptime(user.last_appointment, '%Y-%m-%d')
        now = datetime.datetime.now()
        months = (now.year - l_a.year) * 12 + now.month - l_a.month
        if months > 12:
            alert_dentist = True
            alert_physical = True
        if months > 6:
            alert_physical = True
    if alert_physical and user.phone:
        send_sms(user.phone, 'You need a physical')
        sendEmail(user.email, 'It is time your scheduled physical exam.')
    if alert_dentist and user.phone:
        send_sms(user.phone, 'You need to visit a dentist')
        sendEmail(user.email, 'It is time your scheduled dental exam.')
    return render_template('home.html',
                           form=user_edit_form,
                           alert_physical=alert_physical,
                           alert_dentist=alert_dentist)
예제 #8
0
def edit_profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        if User.authenticate(g.user.username, form.password.data):
            try:
                g.user.username = form.username.data
                g.user.email = form.email.data
                g.user.image_url = form.image_url.data
                g.user.header_image_url = form.header_image_url.data
                g.user.bio = form.bio.data

                db.session.commit()
                return redirect(f"/users/{g.user.id}")
            except IntegrityError:
                flash('Invalid form field', "danger")

        else:
            flash('Invalid password.', "danger")

    return render_template('users/edit.html', form=form, user=g.user)
예제 #9
0
def change_user_settings(username):
    """Handle user settings change."""

    # Make sure the logged in user is the authorized user to view this page.
    if "username" not in session or username != session['username']:
        raise Unauthorized()

    user = User.query.filter_by(username=username).first()

    form = UserEditForm(obj=user)

    if form.validate_on_submit():
        user_auth = User.authenticate(form.username.data, form.password.data)

        if user_auth:
            user.username = form.username.data
            user.email = form.email.data
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.img_url = form.img_url.data or None

            db.session.commit()

            flash("Update Successful.", "success")
            return redirect(f'/users/{user.username}')

        else:
            flash("Incorrect password.", "danger")
            return redirect(f'/users/{user.username}/settings')

    return render_template('/user/settings.html', form=form)
예제 #10
0
파일: views.py 프로젝트: asuvorov/mvp
def edit_profile(request):
    user = request.user
    try:
        profile = UserProfile.objects.get(user=user)
    except:
        profile = UserProfile()

    pform = UserEditForm(request.user, request.POST or None, instance=profile)

    if request.method == "POST":
        if pform.is_valid():
            # Update User
            user.first_name = pform.cleaned_data["first_name"]
            user.last_name = pform.cleaned_data["last_name"]
            #user.email = pform.cleaned_data["email"]
            user.save()
            pform.save()

            return HttpResponseRedirect('/accounts/profile/view/')

    return render_to_response('account_edit.html',
            RequestContext(request, {
                    "pform": pform,
                    "profile": profile,
                    }))
예제 #11
0
def profile_edit():
    """ Renders form to edit the profile or process the information """

    if not 'CURR_USER_KEY' in session:
        flash("Unauthorized access. Account needed to edit profile.", "danger")
        if 'GUEST_GEOCODE' in session:
            return redirect("/search")
        else:
            return redirect("/")

    form = UserEditForm(obj=g.user, prefix='form-user-edit-')

    if form.validate_on_submit():
        user = User.login(form.email.data, form.password.data)
        if (user.id == g.user.id):
            user.first_name = form.first_name.data
            user.display_name = form.display_name.data
            user.profile_pic = form.profile_pic.data
            user.lat = form.lat.data
            user.long = form.long.data
            user.privacy = form.privacy.data
            user.seeking_project = form.seeking_project.data
            user.seeking_help = form.seeking_help.data
            db.session.commit()

            flash("Profile edited successfully.", "success")
            return redirect("/search")
        else:
            flash("Incorrect password. Profile changes not made", "danger")
            return redirect("/profile/edit")
    return render_template("profile-edit.html", form=form)
예제 #12
0
파일: app.py 프로젝트: pedrojperez1/warbler
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)
    if form.validate_on_submit():
        user = User.authenticate(form.username.data, form.password.data)
        if not user:
            flash('Incorrect password provided. Profile update unsuccessful.', 'danger')
            return redirect('/')
        else:
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data
            db.session.add(user)
            db.session.commit()
            flash('Successfully updated your profile!', 'success')
            return redirect(f'/users/{user.id}')
    else:
        return render_template('users/edit.html', form=form)
예제 #13
0
파일: app.py 프로젝트: GroverW/warbler
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        if not User.authenticate(g.user.username, form.data["password"]):
            flash("Invalid password.", "danger")
            return render_template('/users/edit.html', form=form)  
        # data = {k:v for k,v in form.data.items() if k != "csrf_token"}
        # data["image_url"] = data["image_url"] or None
        # data["header_image_url"] = data["header_image_url"] or None

        g.user.username = form.data["username"]
        g.user.email = form.data["email"]
        g.user.image_url = form.data["image_url"] or None
        g.user.header_image_url = form.data["header_image_url"] or None
        g.user.bio = form.data["bio"]

        db.session.commit()

        flash("Profile edited!", "success")
        return redirect(f'/users/{g.user.id}')

    return render_template('/users/edit.html', form=form) 
예제 #14
0
파일: app.py 프로젝트: alevitz/warbler
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")
    else:
        form = UserEditForm(obj=g.user)

        if form.validate_on_submit():
            user = User.authenticate(form.username.data, form.password.data)

            if user:
                flash(f"Hello, {user.username}!",
                      "you have updated your profile!")
                user.username = form.username.data,
                user.email = form.email.data,
                user.image_url = form.image_url.data
                user.header_image_url = form.header_image_url.data
                user.location = form.location.data
                user.bio = form.bio.data

                db.session.commit()

                return redirect(f"/users/{user.id}")

            else:
                flash("Invalid credentials.", 'danger')
                return redirect("/")

        return render_template('users/edit.html', form=form)
예제 #15
0
def profile():
    """Update profile for current user."""
    # if user is logged in
    if g.user:
        # if they subbmited the form
        # user = User.query.get_or_404(session[CURR_USER_KEY])
        form = UserEditForm(obj=g.user)

        if form.validate_on_submit():
            # validate password
            if User.authenticate(g.user.username, request.form["password"]):
                g.user.username = request.form["username"]
                g.user.email = request.form["email"]
                g.user.image_url = request.form["image_url"] or None
                g.user.header_image_url = request.form[
                    "header_image_url"] or None
                g.user.bio = request.form["bio"] or None
                db.session.commit()
                flash("Sucessfully updated", "success")
                return redirect(f"users/{g.user.id}")
            else:
                flash("Wrong password!", "danger")
                return redirect("/users/profile")
        else:
            return render_template("/users/edit.html",
                                   form=form,
                                   user_id=g.user.id)
    else:
        flash('Please login', "info")
        redirect("/login")
예제 #16
0
파일: views.py 프로젝트: hisoka999/silverbb
def base_profile(request):
    f_password = forms.PasswordChangeForm(request.POST)
    f_profile = ProfileForm(instance=request.user.profile)
    f_user = UserEditForm(instance=request.user)
    commit = False
    if request.method == "POST":
        f_profile = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
        f_user = UserEditForm(request.POST, request.FILES, instance=request.user)
        if f_password.is_valid():
            f_password.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            f_profile.save(commit=True)
            commit = True
        if f_profile.is_valid():
            f_profile.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            commit = True
        if f_user.is_valid():
            user = f_user.save(commit=True)
            commit = True
    return render_to_response(
        "user/profile.html",
        {"profile": f_profile, "f_pw": f_password, "f_user": f_user, "commit": commit},
        context_instance=RequestContext(request),
    )
예제 #17
0
def edit_user(user_id):
    """handle form submission for updating user"""
    if not g.user:
        flash("Please login.", "error")
        return redirect("/")

    form = UserEditForm()

    username = form.username.data

    db.session.commit()

    user = g.user

    if form.validate_on_submit():

        if User.authenticate(user.username, form.password.data):

            user.username = form.username.data

            db.session.commit()

        flash(f"Your new username is {user.username}.")

        return redirect(f"/users/{user.id}")

    else:

        flash("Wrong password, please try again.", 'danger')

    return redirect(f'/users/{user.id}/edit')
예제 #18
0
파일: app.py 프로젝트: KortesmakiAB/Warbler
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        user = User.check_hashed_pw_match(g.user.password, form.password.data)
        if not user:
            flash("Invalid username/password.", "danger")
            return render_template('users/edit.html', form=form)

        g.user.username = form.username.data
        g.user.email = form.email.data
        g.user.image_url = form.image_url.data or User.image_url.default.arg
        g.user.header_image_url = form.header_image_url.data
        g.user.bio = form.bio.data
        g.user.location = form.location.data

        try:
            db.session.commit()

        except IntegrityError:
            db.session.rollback()
            flash("Username/Email already taken", 'danger')
            return render_template('users/edit.html', form=form)

        return redirect(f"/users/{g.user.id}")

    return render_template("/users/edit.html", form=form)
예제 #19
0
def profile():
    """Update profile for current user."""

    #  IMPLEMENT THIS
    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    user = User.query.get_or_404(session[CURR_USER_KEY])
    form = UserEditForm(obj=user)

    if form.validate_on_submit():
        # check password valid
        auth_user = User.authenticate(form.username.data, form.password.data)
        if not auth_user:
            # if password not valid flash message
            flash("Invalid Password", "danger")
            return redirect("/")

        user.email = form.email.data
        user.image_url = form.image_url.data
        user.header_image_url = form.header_image_url.data
        user.bio = form.bio.data
        user.location = form.location.data

        # update user in db
        db.session.add(user)
        db.session.commit()

        flash("User Profile Updated", "success")
        return redirect(f"/users/{user.id}")

    return render_template("users/edit.html",
                           form=form)  # templates/users/edit.html
예제 #20
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        if not User.authenticate(g.user.username, form.password.data):
            flash("Profile update unsuccessful.", "danger")
            return render_template("users/edit.html", form=form)

        g.user.username = form.username.data
        g.user.email = form.email.data
        g.user.image_url = (form.image_url.data or DEFAULT_IMAGE_URL)
        g.user.header_image_url = (form.header_image_url.data
                                   or DEFAULT_HEADER_IMAGE_URL)
        g.user.bio = form.bio.data
        g.user.location = form.location.data

        db.session.commit()
        flash(f"{g.user.username}'s information has been successfully updated",
              "success")

        return redirect(f"/users/{g.user.id}")
    else:
        return render_template("users/edit.html", form=form)
예제 #21
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    user_key = session['curr_user']
    user = User.query.get_or_404(user_key)
    form = UserEditForm(obj=user)

    if form.validate_on_submit():
        user.username = form.username.data
        user.email = form.email.data
        user.image_url = form.image_url.data
        user.header_image_url = form.header_image_url.data
        user.bio = form.bio.data

        user = User.authenticate(user.username, form.password.data)

        if user:
            db.session.commit()
            return redirect(f'/users/{g.user.id}')

        flash('password does not match', 'danger')

    return render_template("/users/edit.html", form=form, user=user)
예제 #22
0
def edit_user_details():
    """This view function allows a user to edit their information."""

    if not g.user:
        flash("Access Unauthorized", "danger")
        return redirect("/")

    user = g.user
    form = UserEditForm(obj=user)

    if form.validate_on_submit():
        # Make sure the user editing the profile has the right credentials
        authenticated = User.authenticate(form.username.data,
                                          form.password.data)

        if authenticated:
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data
            user.header_url = form.header_url.data
            user.bio = form.bio.data

            db.session.commit()
            flash("Profile succesfully updated!", "success")
            return redirect(f"/users/{user.id}")

        flash("Wrong password, try again", "danger")

    return render_template("/users/user_edit.html", form=form, user_id=user.id)
예제 #23
0
파일: app.py 프로젝트: neecholai/warbler
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        g.user.email = form.email.data
        g.user.image_url = form.image_url.data
        g.user.location = form.location.data
        g.user.bio = form.bio.data
        g.user.header_image_url = form.header_image_url.data

        user = User.authenticate(g.user.username, form.password.data)
        g.user.username = form.username.data

        if not user:
            flash("Please enter correct user password", "danger")
            return redirect('/users/profile')

        db.session.commit()
        return redirect(f"/users/{g.user.id}")

    return render_template('users/edit.html', form=form)
예제 #24
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        # return redirect("/")
        return redirect(url_for('homepage'))

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        user = User.authenticate(g.user.username, form.password.data)

        if not user:
            flash(f"Incorrect Password!", "danger")
            # return redirect("/")
            return redirect(url_for('homepage'))

        user.username = form.username.data
        user.email = form.email.data
        user.image_url = form.image_url.data
        user.header_image_url = form.header_image_url.data
        user.bio = form.bio.data
        user.location = form.location.data

        db.session.add(user)
        db.session.commit()

        # return redirect(f'/users/{user.id}')
        return redirect(url_for('show_user', user_id=user.id))

    else:
        return render_template('/users/edit.html', form=form)
예제 #25
0
def edit_user(user_id):
    """Shows user profile page"""

    form = UserEditForm()
    user = User.query.get_or_404(user_id)

    if g.user != user:
        flash("Not authorized to view this page.", "danger")
        return redirect(url_for("homepage"))

    if form.validate_on_submit():
        user = User.authenticate(user.username, form.password.data)
        if user:
            try:
                user.edit(
                    form.username.data,
                    form.email.data,
                    form.image_url.data,
                )
            except (IntegrityError, InvalidRequestError) as e:
                db.session.rollback()
                flash("Username already taken", "danger")
                return redirect(url_for("edit_user", user_id=g.user.id))

            flash("Profile updates successful.", "success")
            return redirect(url_for("user_profile", user_id=user.id))
        else:
            flash("Password incorrect.", "danger")
            return redirect(url_for("edit_user", user_id=g.user.id))

    return render_template("users/edit.html", form=form, user=user)
예제 #26
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    user = g.user
    form = UserEditForm(obj=user)

    if form.validate_on_submit():

        authenticated = User.authenticate(form.username.data,
                                          form.password.data)

        if authenticated:
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data

            db.session.commit()
            return redirect(f"/users/{user.id}")

        flash("Wrong password, try again!", 'danger')

    return render_template('users/edit.html', form=form, user_id=user.id)
예제 #27
0
파일: app.py 프로젝트: rayjc/warbler
def profile():
    """Update profile for current user."""

    status_code = 200
    form = (
        # populate form with user object initially
        UserEditForm.new_custom_form(g.user) if request.method == "GET" else
        # populate form with form data
        UserEditForm(request.form))

    if (form.validate_on_submit()
            and User.authenticate(g.user.username, form.password.data)):
        form.update_default(
            g.user)  # replace empty form fields with default values
        form.populate_obj(g.user)
        try:
            db.session.commit()
        except IntegrityError:
            flash(f"Failed to update {g.user.username}", "danger")
            return redirect(url_for('homepage'))

        return redirect(url_for('users_show', user_id=g.user.id))

    elif (form.password.data and
          not User.authenticate(g.user.username, form.data.get('password'))):
        # render the existing form instead of redirecting
        flash(f"Failed to verify password!", "danger")
        form.password.errors.append("Incorrect password")
        status_code = 400
    elif (request.method == "POST" and not form.validate_on_submit()):
        status_code = 400

    return (render_template('users/edit.html', form=form), status_code)
예제 #28
0
파일: app.py 프로젝트: lpagac/warbler
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    curr_username = g.user.username

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        if User.authenticate(curr_username, form.password.data):
            g.user.username = form.username.data
            g.user.email = form.email.data
            g.user.image_url = (
                form.image_url.data or
                DEFAULT_IMAGE_URL
            )
            g.user.header_image_url = (
                form.header_image_url.data or
                DEFAULT_HEADER_IMAGE_URL
            )
            g.user.bio = form.bio.data
            g.user.location = form.location.data
            db.session.commit()

            flash("User has been edited!", "success")
            return redirect(f"/users/{g.user.id}")
        else:
            flash("Incorrect password", "danger")
            return redirect("/")
    return render_template('users/edit.html', form=form)
예제 #29
0
파일: views.py 프로젝트: HanabiDev/Ursus
def edit_user(request, user_id):

	user = User.objects.get(id=user_id)

	if request.method == 'GET':
		
		form = UserEditForm(instance=user)
		if user.type == 'E':
			form = UserEditForm(initial={'role': user.role}, instance=user)

		return render_to_response('edit_user.html', {'form':form, 'site_user':user}, 
						context_instance=RequestContext(request))

	if request.method == 'POST':
		form = UserEditForm(request.POST, instance=user)

		if form.is_valid():

			user = form.save()

			if request.FILES:
				user.avatar = request.FILES.get('avatar')
			
			user.save()

			if user.type == 'C':
				return redirect(reverse_lazy('admin:users:clients'))
			
			return redirect(reverse_lazy('admin:users:employees'))


    	return render_to_response('edit_user.html', {'form':form, 'site_user':user}, 
						context_instance=RequestContext(request))
예제 #30
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")
    edit_user = User.query.get_or_404(g.user.id)
    form = UserEditForm(obj=edit_user)

    if form.validate_on_submit():
        user = User.authenticate(username=g.user.username,
                                 password=form.password.data)
        if user:
            edit_user.username = form.username.data
            edit_user.username = form.username.data
            edit_user.email = form.email.data
            edit_user.img_url = form.image_url.data
            edit_user.header_url = form.image_url.data
            edit_user.bio = form.bio.data
            sess.commit()
        else:
            flash("Incorrect Password to Edit Profile.")
            return render_template("users/edit.html", form=form)
        return redirect(f'/users/{g.user.id}')
    else:
        return render_template("users/edit.html", form=form)
예제 #31
0
def profile():
    """Update profile for current user."""

    # IMPLEMENT THIS
    if not g.user:

        flash('Access unauthorized.', 'danger')
        return redirect('/')

    else:

        user = User.query.get_or_404(session[CURR_USER_KEY])
        form = UserEditForm(obj=user)

        if form.validate_on_submit():

            if User.authenticate(user.username, form.password.data):

                User.update(user, form)

                return redirect(f'/users/{user.id}')

            else:

                form.password.errors = ['Incorrect Password']
                return render_template('users/edit.html', form=form)

        return render_template('users/edit.html', form=form)
예제 #32
0
def edit_profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = UserEditForm(obj=g.user)

    if form.validate_on_submit():
        if User.authenticate(g.user.username, form.static_password.data):
            form.populate_obj(g.user)

            try:
                db.session.commit()
                return redirect(f"/users/{g.user.id}")
            except IntegrityError:
                db.session.rollback()
                flash("That username or email is already taken")
                return render_template('users/edit.html', form=form,
                                       user_id=g.user.id)

        flash("Wrong password, please try again.", 'danger')

    return render_template('users/edit.html', form=form, user_id=g.user.id)
예제 #33
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect('/')

    user = g.user
    update_user_form = UserEditForm(obj=user)

    if update_user_form.validate_on_submit():  #if form okay (it's a POST)
        if User.authenticate(
                g.user.username,
                update_user_form.password.data):  #if user authenticated ok
            user.username = update_user_form.username.data
            user.email = update_user_form.email.data
            user.image_url = update_user_form.image_url.data or "/static/images/default-pic.png"
            user.header_image_url = update_user_form.header_image_url.data or "/static/images/warbler-hero.jpg"
            user.bio = update_user_form.bio.data

            db.session.commit()
            return redirect(f'/users/{g.user.id}')
        else:
            flash("Incorrect password, please try again.", "danger")

    return render_template('/users/edit.html',
                           form=update_user_form,
                           user_id=user.id)  #this one actually shows the page
예제 #34
0
def me_edit():
	form = UserEditForm(obj=current_user.profile)
	if form.validate_on_submit():
		current_user.profile.name = form.name.data
		current_user.profile.bio = form.bio.data
		db.session.commit()
		return redirect(url_for('.me'))
	return render_template('users/me_edit.html', user=current_user, form=form)
예제 #35
0
def edit_user(request):
	if request.user.is_authenticated():
		# Gets user info of the current user logged in the system
		if request.method == 'POST':
			form = UserEditForm(request.POST, instance=request.user)
			if form.is_valid():
				form.save()
				return HttpResponseRedirect('/')
		else:
			form = UserEditForm(instance=request.user)
		c = {'form': form}
		return render_to_response("edit_user.html", c, context_instance=RequestContext(request))
예제 #36
0
파일: views.py 프로젝트: ddub/intbass
def edituser(id):
    user = load_user(id)
    form = UserEditForm()
    #if form.validate_on_submit():
    if form.is_submitted():
        if form.username.data != user.name:
            try:
                user.name=form.username.data
                db.session.commit()
                flash('Username change from ' + user.name + ' to ' + form.username.data, 'success')
            except:
                flash('Username change error', 'error')
        if form.password.data != '':
            try:
                user.password = sha256(request.form['password']).hexdigest()
                db.session.commit()
                flash('Password changed', 'success')
            except:
                flash('Password change error.', 'error')
        if form.email.data != user.email:
            try:
                user.email = form.email.data
                db.session.commit()
                flash('Email changed to ' + user.email, 'success')
            except:
                flash('Email change error', 'error')
        if form.location.data != user.location:
            try:
                user.location = form.location.data
                db.session.commit()
                flash('Location changed to ' + user.location, 'success')
            except:
                flash('Location change error', 'error')
        if int(form.role.data) != user.role:
            try:
                user.role = int(form.role.data)
                db.session.commit()
                flash('Role changed to ' + str(user.role), 'success')
            except:
                flash('Role change error', 'error')

        return render_template('admin/users/edit.html',
                form = form,
                user = user)
    else: 
        form = UserEditForm(username = user.name,
        #role = user.role,
        email = user.email,
        location = user.location)
        return render_template('admin/users/edit.html',
            form = form,
            user = user)
예제 #37
0
def update_account():
    user = app.current_user
    update_form = UserEditForm(request.POST, user)
    if update_form.validate():
        # user.update(**update_form.data).execute()
        update_form.populate_obj(user)
        print(update_form.data)
        user.save()
        print(user.picture)
        app.flash(u'Дані успішно оновлено')
    else:
        app.flash(u'Incorrect somtethisd')
    redirect('/account')  # without return redirect because of raise inside
예제 #38
0
파일: views.py 프로젝트: agar3s/recluta
def userProfileEditView(request):
    user = request.user
    if request.method== 'POST':
        form = UserEditForm(request.POST)
        if form.is_valid():
            user_profile_factory = UserProfileFactory()
            user_profile_factory.save_instance_form(form=form, user=user)
            return HttpResponseRedirect("/")
    else:
        form_loader = UserEditFormLoader()
        form = form_loader.load_initial_data(user)
    ctx = {'form':form}
    return render_to_response('edit_profile.html',ctx,context_instance=RequestContext(request))
예제 #39
0
def user_add():
    form = UserEditForm(request.form)
    form.team_id.choices = [(1, u'管理'), (2, u'运维监控'), (3, u'信号采集'), (4, u'网络存储'), \
        (5, u'机房运维'), (6, u'直播流运营')]
    form.team_id.choices.insert(0, (0, u'- 指定团队 -'))

    if form.validate_on_submit():
        user = User(form.name.data, form.email.data, form.qq.data, form.mobile.data, form.password.data, \
            form.team_id.data, form.active.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('user_list'))

    return render_template('user_edit.html', form=form)
예제 #40
0
파일: admin.py 프로젝트: alioth310/cipher
    def post(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        arguments = {
                'username': self.get_argument("username"),
                'email': self.get_argument("email"),
                'password': self.get_argument("password"),
                'status': self.get_argument("status"),
                'group': self.get_argument("group"),
        }

        form = UserEditForm(self.request.arguments)
        form.status.choices = [(k, v) for k, v in self.status_name.iteritems()]
        form.status.choices.sort()
        form.group.choices = [(k, v) for k, v in self.group_name.iteritems()]
        form.group.choices.sort()
        
        user_info = get_user_info_by_id(self.session, id)
        if user_info is None:
             self.render("404.html", username=self.username, group=self.group)
        update_error = user_update_validation(self.session, 
                user_info, self.uid, arguments)
        
        if form.validate():
            if update_error == "":
                update_user_info(self.session, user_info, arguments)
                self.redirect("/admin/user/show/" + id)
            else:
                self.render(
                        "admin/user_edit.html", 
                        username=self.username,
                        group=self.group, 
                        status_name=self.status_name,
                        group_name=self.group_name, 
                        form=form,
                        db_error=update_error, 
                        user_info=user_info
                )
        else:
            self.render(
                    "admin/user_edit.html", 
                    username=self.username,
                    group=self.group, 
                    status_name=self.status_name,
                    group_name=self.group_name, 
                    form=form, 
                    db_error=None,
                    user_info=user_info
            )
예제 #41
0
def edit(request, user_id):
    if request.user.id != int(user_id):
        return redirect(reverse('home'))
    user = User.objects.get(id=user_id)
    if request.method == 'POST':
        form = UserEditForm(request.POST, instance=user)
        if form.is_valid():
            edited_user = form.save()
            messages.success(request, 'Profile successfully edited.')
            return redirect(edited_user)
    else:
        form = UserEditForm(instance=user)

    return render(request, 'accounts/edit.html', {'form': form,
                                                  'user': user})
예제 #42
0
def user_edit(id):
    user = User.query.filter(User.id==id).first()
    form = UserEditForm(request.form, user)
    form.team_id.choices = [(1, u'管理'), (2, u'运维监控'), (3, u'信号采集'), (4, u'网络存储'), \
        (5, u'机房运维'), (6, u'直播流运营')]
    form.team_id.choices.insert(0, (0, u'- 指定团队 -'))

    if form.validate_on_submit():
        form.populate_obj(user)

        if form.password.data != '':
            user.set_password(form.password.data)
        
        db.session.commit()
        return redirect(url_for('user_list'))

    return render_template('user_edit.html', form=form)
예제 #43
0
파일: views.py 프로젝트: booya/intbass
def edituser(id):
    user = load_user(id)
    form = UserEditForm()
    #if form.validate_on_submit():
    if form.is_submitted():
        if form.name.data != user.name:
            try:
                user.name=form.name.data
                db.session.commit()
                flash('Username change from ' + user.name + ' to ' + form.name.data, 'success')
            except:
                flash('Username change error', 'error')
        if form.password.data != '':
            try:
                user.password = form.password.data
                db.session.commit()
                flash('Password changed', 'success')
            except:
                flash('Password change error.', 'error')
        if form.email.data != user.email:
            try:
                user.email = form.email.data
                db.session.commit()
                flash('Email changed to ' + user.email, 'success')
            except AssertionError:
                flash('Invalid email address', 'error')
            except:
                flash('Email change error', 'error')
        if form.location.data != user.location:
            try:
                user.location = form.location.data
                db.session.commit()
                flash('Location changed to ' + user.location, 'success')
            except:
                flash('Location change error', 'error')

        return render_template('admin/users/edit.html',
                form = form,
                user = user)
    else: 
        form = UserEditForm(obj=user)
        return render_template('admin/users/edit.html',
            form = form,
            user = user)
예제 #44
0
def publisher_settings_users_edit(request, id):
    ''' View to edit a Publisher's User '''
    from atrinsic.base.models import User
    from forms import UserEditForm
    
    try:
        u = User.objects.get(id=id)

        if request.organization not in u.userprofile_set.all()[0].organizations.all():
            raise Http404

    except User.DoesNotExist:
        raise Http404

    if request.method == "POST":
        form = UserEditForm(request.POST)
        form.user_id = u.id

        if form.is_valid():
            u.first_name = form.cleaned_data['first_name']
            u.last_name = form.cleaned_data['last_name']
            u.email = form.cleaned_data['email']
            u.username = u.email.replace('@', '-')

            if form.cleaned_data.get("password",None):
                u.set_password(form.cleaned_data['password'])

            u.save()

            return HttpResponseRedirect('/publisher/settings/users/')
    else:
        form = UserEditForm(initial={
                'first_name' : u.first_name,
                'last_name' : u.last_name,
                'email' : u.email,
            })

    return AQ_render_to_response(request, 'publisher/settings/users-edit.html', {
            'u' : u,
            'form' : form,
        }, context_instance=RequestContext(request))
예제 #45
0
def edit(request):

    user = request.user
    f = get_object_or_404(Farmer, user=user)
    u = user

    if request.method == 'POST':
        form = FarmerForm(request.POST, instance=f)
        uform = UserEditForm(request.POST, instance=u)

        if uform.is_valid() and form.is_valid():
            uform.save()
            form.save()

            return redirect(reverse('home'))
    else:
        form = FarmerForm(instance=f)
        uform = UserEditForm(instance=u)

    return render(request, 'registration/edit.html', {
        'form': form,
        'uform': uform
    })
예제 #46
0
def edit_user(request):
    context = {}

    if request.method == 'POST':
        form = UserEditForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            email = form.cleaned_data['email']
            phone = form.cleaned_data['phone']
            new_password =  form.cleaned_data['new_password']
            new_password_confirm = form.cleaned_data['new_password_confirm']

            error = False
            if new_password and new_password_confirm:
                if (new_password != new_password_confirm):
                    # 400
                    form.errors['__all__'] = form.error_class(["Error: passwords didn't match."])
                    error = True
            elif (new_password and not new_password_confirm) or (new_password_confirm and not new_password):
                # 400
                form.errors['__all__'] = form.error_class(["Error: you must input the desired password twice."])
                error = True
            else:
                new_password = None

            if not error:
                user = users_manager.update_user(request.user, first_name, last_name, new_password, email, phone)
                context['success'] = not error
    else:
        data = {'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email,
                'phone': request.user.profile.phone,}
        form = UserEditForm(data)

    # GET / POST with invalid input
    context['form'] = form
    return render_to_response('user/edit.html', context, context_instance=RequestContext(request))