def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(g.user.id) user = user_contr.get(id=g.user.id) form = ProfileForm() if request.method == "POST": if form.validate(): user_contr.update( {"id": g.user.id}, { "nickname": form.nickname.data, "email": form.email.data, "password": form.password.data, "refresh_rate": form.refresh_rate.data, }, ) flash(gettext("User %(nick)s successfully updated", nick=user.nickname), "success") return redirect(url_for("user.profile")) else: return render_template("profile.html", user=user, form=form) if request.method == "GET": form = ProfileForm(obj=user) return render_template("profile.html", user=user, form=form)
def updateprofile(request): if request.method == 'POST': profile_form = ProfileForm(request.POST) if profile_form.is_valid(): try: userprofile_object = UserProfile.objects.get(user=request.user) userprofile_object.phone_number = profile_form.cleaned_data[ 'phone_number'] userprofile_object.save() user_object = User.objects.get(pk=request.user.id) user_object.first_name = profile_form.cleaned_data[ 'first_name'] user_object.last_name = profile_form.cleaned_data['last_name'] user_object.save() messages.add_message( request, messages.SUCCESS, "Your Profile Updated Successfully" ) # except IntegrityError as error: # messages.add_message(request, messages.ERROR, error) except Exception as e: messages.add_message(request, messages.ERROR, e) return redirect("/accounts/dashboard/") else: messages.add_message(request, messages.ERROR, profile_form.errors) return redirect("/accounts/dashboard/") else: messages.add_message(request, messages.ERROR, 'You Should USE POST METHOD IN REQUEST') return redirect("/accounts/dashboard/")
def profile(): user = User.query.filter(User.id==current_user.id).first() form = ProfileForm() # form.set_languages_choice() if request.method == 'POST': if form.validate(): # update user if form.password.data and \ form.password.data == form.password_conf.data: user.set_password(form.password.data) form.populate_obj(user) db.session.commit() flash('User successfully updated', 'success') return redirect(url_for('user_bp.profile')) else: flash('User update failed', 'danger') return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI) if request.method == 'GET': form = ProfileForm(obj=user) return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI)
def profile_update(user_id): ucontr = None if admin_permission.can(): ucontr = UserController() elif Permission(UserNeed(user_id)).can(): ucontr = UserController(user_id) else: flash(gettext('You do not have rights on this user'), 'danger') raise Forbidden(gettext('You do not have rights on this user')) user = ucontr.get(id=user_id) profile_form, pass_form = ProfileForm(obj=user), PasswordModForm() if profile_form.validate(): values = {'login': profile_form.login.data, 'email': profile_form.email.data} if admin_permission.can(): values['is_active'] = profile_form.is_active.data values['is_admin'] = profile_form.is_admin.data values['is_api'] = profile_form.is_api.data ucontr.update({'id': user_id}, values) flash(gettext('User %(login)s successfully updated', login=user.login), 'success') return redirect(url_for('user.profile', user_id=user.id)) return render_template('profile.html', user=user, admin_permission=admin_permission, form=profile_form, pass_form=pass_form)
def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(g.user.id) user = user_contr.get(id=g.user.id) form = ProfileForm() if request.method == 'POST': if form.validate(): user_contr.update({'id': g.user.id}, { 'nickname': form.nickname.data, 'email': form.email.data, 'password': form.password.data, 'refresh_rate': form.refresh_rate.data }) flash( gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') return redirect(url_for('user.profile')) else: return render_template('profile.html', user=user, form=form) if request.method == 'GET': form = ProfileForm(obj=user) return render_template('profile.html', user=user, form=form)
def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(current_user.id) user = user_contr.get(id=current_user.id) form = ProfileForm() if request.method == 'POST': if form.validate(): try: user_contr.update({'id': current_user.id}, {'nickname': form.nickname.data, 'email': form.email.data, 'password': form.password.data, 'automatic_crawling': form.automatic_crawling.data, 'is_public_profile': form.is_public_profile.data, 'bio': form.bio.data, 'webpage': form.webpage.data, 'twitter': form.twitter.data}) except Exception as error: flash(gettext('Problem while updating your profile: ' '%(error)s', error=error), 'danger') else: flash(gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') return redirect(url_for('user.profile')) else: return render_template('profile.html', user=user, form=form) if request.method == 'GET': form = ProfileForm(obj=user) return render_template('profile.html', user=user, form=form)
def profile_update(user_id): ucontr = None if admin_permission.can(): ucontr = UserController() elif Permission(UserNeed(user_id)).can(): ucontr = UserController(user_id) else: flash(gettext('You do not have rights on this user'), 'danger') raise Forbidden(gettext('You do not have rights on this user')) user = ucontr.get(id=user_id) profile_form, pass_form = ProfileForm(obj=user), PasswordModForm() if profile_form.validate(): values = { 'login': profile_form.login.data, 'email': profile_form.email.data } if admin_permission.can(): values['is_active'] = profile_form.is_active.data values['is_admin'] = profile_form.is_admin.data values['is_api'] = profile_form.is_api.data ucontr.update({'id': user_id}, values) flash(gettext('User %(login)s successfully updated', login=user.login), 'success') return redirect(url_for('user.profile', user_id=user.id)) return render_template('profile.html', user=user, admin_permission=admin_permission, form=profile_form, pass_form=pass_form)
def form(): user = User.query.filter(User.id == current_user.id).first() form = ProfileForm(obj=user) form.populate_obj(current_user) action = "Edit user" head_titles = [action] head_titles.append(user.login) return render_template('edit_user.html', action=action, head_titles=head_titles, form=form, user=user)
def process_form(): form = ProfileForm() if not form.validate(): return render_template('edit_user.html', form=form) user = User.query.filter(User.id == current_user.id).first() form.populate_obj(user) if form.password.data: user.pwdhash = generate_password_hash(form.password.data) db.session.commit() flash('User {} successfully updated.'. format(form.login.data), 'success') return redirect(url_for('admin_bp.form_user', user_id=user.id))
def profile(): user = User.query.filter(User.id == current_user.id).first() form = ProfileForm() # form.set_languages_choice() if request.method == 'POST': if form.validate(): # update user if form.password.data and \ form.password.data == form.password_conf.data: user.set_password(form.password.data) form.populate_obj(user) db.session.commit() flash('User successfully updated', 'success') return redirect(url_for('user_bp.profile')) else: flash('User update failed', 'danger') return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI) if request.method == 'GET': form = ProfileForm(obj=user) return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI)
def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(current_user.id) user = user_contr.get(id=current_user.id) form = ProfileForm() if request.method == "POST": if form.validate(): try: user_contr.update( {"id": current_user.id}, { "nickname": form.nickname.data, "password": form.password.data, "automatic_crawling": form.automatic_crawling.data, "is_public_profile": form.is_public_profile.data, "bio": form.bio.data, "webpage": form.webpage.data, "twitter": form.twitter.data, }, ) except Exception as error: flash( gettext( "Problem while updating your profile: " "%(error)s", error=error ), "danger", ) else: flash( gettext("User %(nick)s successfully updated", nick=user.nickname), "success", ) return redirect(url_for("user.profile")) else: return render_template("profile.html", user=user, form=form) if request.method == "GET": form = ProfileForm(obj=user) return render_template("profile.html", user=user, form=form)
def setting(request): user = request.user username = user.username if request.method == 'POST': form = ProfileForm(request.POST) if form.is_valid(): new_password = form.cleaned_data.get('new_password') user.set_password(new_password) user.save() message = '修改成功' messages.add_message(request, messages.SUCCESS, message) new_user = authenticate(username=username, password=new_password) login(request, new_user) else: form = ProfileForm(instance=user) return render(request, 'web/setting.html', {'form': form})
def profile(user_id=None): ucontr = None if user_id and admin_permission.can(): ucontr = UserController() elif user_id and Permission(UserNeed(user_id)).can(): ucontr = UserController(user_id) elif user_id: flash(gettext('You do not have rights on this user'), 'danger') raise Forbidden(gettext('You do not have rights on this user')) else: ucontr = UserController(current_user.id) user_id = current_user.id user = ucontr.get(id=user_id) profile_form, pass_form = ProfileForm(obj=user), PasswordModForm() return render_template('profile.html', user=user, admin_permission=admin_permission, form=profile_form, pass_form=pass_form)
def password_update(user_id): ucontr = None if admin_permission.can(): ucontr = UserController() elif Permission(UserNeed(user_id)).can(): ucontr = UserController(user_id) else: flash(gettext('You do not have rights on this user'), 'danger') raise Forbidden(gettext('You do not have rights on this user')) user = ucontr.get(id=user_id) profile_form, pass_form = ProfileForm(obj=user), PasswordModForm() if pass_form.validate(): ucontr.update({'id': user_id}, {'password': pass_form.password.data}) flash( gettext('Password for %(login)s successfully updated', login=user.login), 'success') return redirect(url_for('user.profile', user_id=user.id)) return render_template('profile.html', user=user, admin_permission=admin_permission, form=profile_form, pass_form=pass_form)
def myprofile(request): if request.POST: form = ProfileForm(request.POST, request.FILES) if form.is_valid(): profile_current = form.save(commit=False) profile_current.user = request.user profile_current.save() else: form = ProfileForm() user = request.user if Profile.objects.filter(user=user): profile = Profile.objects.get(user=user) else: profile = None object_list = Article.objects.filter(user=user) topic_list = list(set([x.topic for x in object_list.all()])) print(topic_list) return render( request, "myprofile.html", { "object": profile, "topic_list": topic_list, "object_list": object_list, "form": form })
def profile(): user = User.query.filter(User.id == current_user.id).first() form = ProfileForm() form.set_languages_choice() if request.method == 'POST': if form.validate(): # update user form.populate_obj(user) if form.password.data and \ form.password.data == form.password_conf.data: user.set_password(form.password.data) db.session.commit() flash('User successfully updated', 'success') return redirect(url_for('user_bp.profile')) else: return render_template('profile.html', user=user, form=form) if request.method == 'GET': form = ProfileForm(obj=user) form.set_languages_choice() return render_template('profile.html', user=user, form=form)
def dashboard_page(request): verified = Verification.objects.filter(user=request.user).first() if verified: verified = verified.is_verified else: verified = False ######################## Card Form Place Holders ################ card_form = cardForm() card_form.fields['card_number'].widget.attrs.update( {'placeholder': 'CardNumber'}) card_form.fields['date_exp'].widget.attrs.update( {'placeholder': 'Date Of EXP'}) card_form.fields['cvv'].widget.attrs.update({'placeholder': 'CVV'}) card_form.fields['card_front'].widget.attrs.update( {'placeholder': 'Card Front Side'}) card_form.fields['card_back'].widget.attrs.update( {'placeholder': 'Card Back Side'}) ######################## Verification Form Place Holders ################ verification_form = VerificationForm() verification_form.fields['passport_code'].widget.attrs.update( {'placeholder': 'Passport Code'}) verification_form.fields['country_name'].widget.attrs.update( {'placeholder': 'Country Name'}) verification_form.fields['birth_date'].widget.attrs.update( {'placeholder': 'Date of Birth'}) verification_form.fields['address'].widget.attrs.update( {'placeholder': 'Address'}) verification_form.fields['passport_photo'].widget.attrs.update( {'placeholder': 'Passport Photo'}) ######################## Order Form Place Holders ################ order_form = OrderForm(cards=request.user, coins=coinsselector()) order_form.fields['receipt_code'].widget.attrs.update( {'id': 'nextstep123'}) # order_form.fields['receipt_code'].widget.attrs.update({'style': 'display:none;'}) order_form.fields['blockchain_wallet'].widget.attrs.update( {'id': 'nextstep1234'}) order_form.fields['source_amount'].widget.attrs.update( {'onchange': 'setamount()'}) order_form.fields['source_currency'].widget.attrs.update( {'onchange': 'setamount()'}) order_form.fields['destination_currency'].widget.attrs.update( {'onchange': 'setamount()'}) ######################## ProfileUpdate ########################## profile_form = ProfileForm() profile_form.fields['first_name'].widget.attrs.update( {"value": request.user.first_name}) profile_form.fields['last_name'].widget.attrs.update( {"value": request.user.last_name}) phone_number = UserProfile.objects.filter( user=request.user).first().phone_number profile_form.fields['phone_number'].widget.attrs.update( {"value": phone_number}) ######################## End ################ orders = Order.objects.filter(user=request.user) response = { "title": "Dashboard", "coins": cached(getcoins)(), "dollar": cached(getdollar)(), "card_form": card_form, "Verification_Form": verification_form, "orders": orders, "Order_Form": order_form, "ProfileForm": profile_form, "is_verified": verified } print(response) return render(request, "panel/dashboard.html", context=response)