def account_page(request): if request.method == 'POST': # If the form has been submitted... form = AccountForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass cleaned_data = form.cleaned_data username = cleaned_data['username'] first_name = cleaned_data['first_name'] last_name = cleaned_data['last_name'] email = cleaned_data['email'] password_old = cleaned_data['password_old'] password_new = cleaned_data['password_new'] if authenticate(username=username, password=password_old): u = User.objects.get(username__exact=username) if password_new > '': u.set_password(password_new) if first_name > '': u.first_name = first_name if last_name > '': u.last_name = last_name if email > '': u.email = email u.save() return {'status': 'success'} else: return {'status': 'error', 'message': 'Wrong password!'} else: return {'status': 'error', 'message': 'Invalid form!'} else: form = AccountForm() return render_to_response('account.html', { 'form': form, }, context_instance=RequestContext(request))
def make_account(request): if request.method == 'POST': form = AccountForm(request.POST) if form.is_valid(): return render(request, 'account_info.html', {'data': json.dumps(form.cleaned_data)}) else: form = AccountForm() return render(request, 'account.html', {'form': form})
def create_account(request): """ Create a new email account. """ account_form = AccountForm() if request.method == "POST": account_form = AccountForm(request.POST) if account_form.is_valid(): account = account_form.save(commit=False) account.owner = request.user account.save() messages.success(request, "%s added" % account.email_address) return redirect("view_account", account.id) return render(request, "accounts/create.html", {"form": account_form})
def edit_account(request, pk): """ Edit an email account. """ account = get_object_or_404(SMTPAccount, pk=pk, owner=request.user) account_form = AccountForm(instance=account) if request.method == "POST": account_form = AccountForm(request.POST, instance=account) if account_form.is_valid(): account = account_form.save() messages.success(request, "%s updated" % account.email_address) return redirect("view_account", account.id) return render(request, "accounts/edit.html", { "account": account, "form": account_form })
def get_context_data(self, *args, **kwargs): context = super(AccountSetPasswordView, self).get_context_data(*args, **kwargs) context['object'] = self.get_object() context['form'] = AccountForm(instance=self.get_object()) context['form2'] = PasswordChangeForm(self.get_object(), **self.get_form_kwargs()) return context
def edit(request, object_id, template_name='engine_groups/edit.html'): object = get_one_or_404(id=object_id) if request.method == 'POST': form = AccountForm(request.POST, instance=object) if form.is_valid(): g = form.save() return HttpResponseRedirect(reverse('group', args=[object.id])) else: form = AccountForm(instance=object) template_context = {'form': form, 'new': False} return render_to_response(template_name, template_context, RequestContext(request))
def create_account(): form = AccountForm() completion_msg = "" if form.validate_on_submit(): if form.save.data: new_account = Account(name=form.name.data, pnumber=form.pnumber.data, email=form.email.data, street=form.street.data, city=form.city.data, state=form.state.data, postal=form.postal.data, country=form.country.data, notes=form.notes.data) db.session.add(new_account) try: db.session.commit() except: completion_msg = "Failed to create account. Please try again." if completion_msg == "": completion_msg = "Success! The account has been saved." return redirect(url_for('view_account')) else: completion_msg = "Failed to create account. Please try again." return render_template("create_account.html", form=form, completion_msg=completion_msg)
def view_accounts(): page = request.args.get('page', 1) q = request.args.get('q') accounts = restful.GetAccounts(int(page), q) if not accounts.has_key(restful.ITEM_OBJECTS): return redirect(url_for('view_accounts')) accountforms = [ logic.GetAccountFormById(x[restful.ITEM_ID]) for x in accounts[restful.ITEM_OBJECTS] ] while None in accountforms: accountforms.remove(None) if request.method == 'POST': form = AccountForm(request.form) if request.form.has_key('delete'): orm.db.session.delete(orm.Account.query.get(int(form.id.data))) orm.db.session.commit() return redirect(url_for('view_accounts', page=page, q=q)) form = PageInfo() logic.LoadBasePageInfo('所有用户', '查看', form) return render_template('view_accounts.html', forms=accountforms, form=form, paging=restful.GetPagingFromResult(accounts))
def search_customer(): if request.method == 'GET': account_search = AccountSearchForm() return render_template('account_search.html', user=current_user.type, form=account_search) elif request.method == 'POST': account_search = AccountSearchForm(request.form) account = None if account_search.customer_id.data: account = Account.query.filter_by( ws_cust_id=int(account_search.customer_id.data)).first() elif account_search.account_id.data: account = Account.query.filter_by( act_id=int(account_search.account_id.data)).first() else: flash('Invalid customer') if account: selected_account = AccountForm() selected_account.customer_id.data = account.ws_cust_id selected_account.account_id.data = account.act_id selected_account.account_type.data = 'Savings' if account.ws_acct_type == 'S' else 'Current' selected_account.balance.data = account.ws_acct_balance return render_template('search_customer.html', form=selected_account) else: flash('Account does not exist', 'danger') flash('Please enter a value', 'warning') return redirect(url_for('app.search_customer'))
def edit_account(account_id): account = Account.query.get_or_404(account_id) form = AccountForm(obj=account) completion_msg = "" if form.validate_on_submit(): if form.save.data: account.name = form.name.data account.pnumber = form.pnumber.data account.email = form.email.data account.street = form.street.data account.city = form.city.data account.state = form.state.data account.postal = form.postal.data account.country = form.country.data account.notes = form.notes.data try: db.session.commit() except: completion_msg = "Failed to update account. Please try again." if completion_msg == "": completion_msg = "Success! The account has been saved." return redirect(url_for('view_account')) else: completion_msg = "Failed to update account. Please try again." return render_template("edit_account.html", form=form, completion_msg=completion_msg)
def add_account(): """ Add a account to the database """ check_admin() add_account = True form = AccountForm() if form.validate_on_submit(): account = Account(AccNum=form.AccNum.data, name=form.name.data, AccCategory=form.AccCategory.data, SaccCategory=form.SaccCategory.data, balance=form.balance.data, Comment=form.Comment.data) try: # add department to the database db.session.add(account) db.session.commit() flash('You have successfully added a new entry.') except: # in case department name already exists flash('Error: entry name already exists.') # redirect to departments page return redirect(url_for('admin.list_account')) # load department template return render_template('admin/accounts/account.html', action="Add", add_account=add_account, form=form, title="Add Account")
def save(request): obj = None name = request.POST.get('name') tag = request.POST.get('tag') profile = Profile.objects.get(user_id=request.user.id) try: if request.POST.get('id'): obj = Account.objects.get(id=request.POST.get('id')) except Account.DoesNotExist: pass if obj: form = AccountForm(request.POST or None, instance=obj) else: form = AccountForm(request.POST or None) if form.is_valid(): instance = form.save(commit=False) if request.POST.get('id'): instance.updateuser = request.user password = encrypt(request.POST.get('password'), profile.key[:8] + profile.iv[8:], profile.key[8:] + profile.iv[:8]) if password != obj.password: instance.password = password else: instance.createuser = request.user instance.tag_id = tag instance.password = encrypt(request.POST.get('password'), profile.key[:8] + profile.iv[8:], profile.key[8:] + profile.iv[:8]) instance.save() result = {"ret": 0, "status": "success"} return HttpResponse(json.dumps(result), content_type="application/json") else: msg = [] if form.errors: for k, v in form.errors.iteritems(): msg.append(v[0]) return HttpResponse(json.dumps({ "ret": 10000, "status": "error", "msg": '\n'.join(msg) }), content_type="application/json")
def account_edit(request, response_format='html'): "Account edit" profile = request.user.profile if request.POST: form = AccountForm(request.POST, instance=profile) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('account_view')) else: form = AccountForm(instance=profile) return render_to_response('account/account_edit', { 'profile': profile, 'form': Markup(form.as_ul()) }, context_instance=RequestContext(request), response_format=response_format)
def show_account(account_id): account = Account.get_by_id(account_id) subscriptions = account.get_subscriptions(active_only=True) form = AccountForm(obj=account) return render_template("account.html", form=form, account=account, subscriptions=subscriptions)
def do_create_account(): form = AccountForm(request.form) account = Account() form.populate_obj(account) if form.validate_on_submit(): account.save() return redirect(url_for("app_blueprint.show_accounts")) return render_template("account.html", form=form), 400
def account_add(request, shortcode=None): account = None if request.method == "POST": form = AccountForm(request.POST, instance=account) if form.is_valid(): account = form.save() request.user.accounts.create( account=account, role=UserAccount.ROLE_OWNER, ) return HttpResponseRedirect(reverse("index")) else: form = AccountForm(instance=account) return render(request, "account_form.html", { "form": form, "account": account })
def index_bak(request): pwd_forms = ChangeForm() forms = AccountForm() tags = Tag.objects.all() template = loader.get_template('account.html') context = { "account": "active", "forms": forms, "tags": tags, "username": request.user.username, "pwd_forms": pwd_forms } return HttpResponse(template.render(context, request))
def GetAccountFormById(account_id): account = orm.Account.query.get(int(account_id)) if account is None: return None accountform = AccountForm() accountform.id.data = account.id accountform.username.data = account.username accountform.password.data = account.password accountform.name.data = account.name accountform.telephone.data = account.telephone accountform.flag_telephone.data = True if account.flag_telephone > 0 else False accountform.checkcode.data = account.checkcode accountform.source.data = account.source accountform.dtcreate.data = account.dtcreate return accountform
def home(request): #region GET if request.method == "GET": form_capcha = CaptchaTestForm() form_account = AccountForm() html_dtc = dict(form_capcha=form_capcha, form_account=form_account, count=len(AccountModel.objects.all())) error_message = request.session.get('error_message', False) if error_message: html_dtc.update(dict(error_message=error_message)) del request.session['error_message'] html_dtc.update(csrf(request)) return render_to_response('chikun/home.html', html_dtc) #endregion #region POST if request.method == "POST": # human test form = CaptchaTestForm(request.POST) if not form.is_valid(): request.session.update(dict(error_message='Invalid Captcha')) return redirect('home') # validate return address return_address = request.POST.get('return_address', False) if not is_address_valid(return_address): request.session.update( dict(error_message='Invalid Bitcoin Address')) return redirect('home') # log details account_record = AccountModel.objects.create( return_address=return_address) account_record.save() # deposit address deposit_address = master_public_key.subkey(account_record.id).address() # html tags html_dtc = dict(deposit_address=deposit_address) html_dtc.update(csrf(request)) return render_to_response('chikun/address.html', html_dtc) ''''''
def account(): if request.method == "GET": form = AccountForm(obj=current_user) else: form = AccountForm(request.form) try: subscribed = Subscription.objects.get(user=current_user.pk) except Subscription.DoesNotExist: subscribed = None if not request.method == 'POST' or not form.validate(): context = {'form': form, 'subscribed': subscribed} return render_template('account.html', **context) if form.username.data: current_user.username = form.username.data if form.email.data: current_user.email = form.email.data if form.phone.data: current_user.phone = form.phone.data if form.address.data: current_user.address = form.address.data if form.subscribe.data: current_user.subscribe = form.subscribe.data if form.password.data: current_user.set_password(form.password.data) try: current_user.save() except Exception, e: print str(e)
def account_add(request): """Add a new mail account. :param request: the request object :returns: an edit form template """ form = AccountForm(request.POST or None) form.fields['domain'].queryset = get_domains(request.user) if form.is_valid(): ac = form.save(commit=False) ac.set_password(form.cleaned_data['password']) ac.save() return redirect('limeade_mail_account_list') return render_to_response("limeade_mail/account_add.html", {"form": form}, context_instance = RequestContext(request))
def register(request): if request.method == 'POST': acct_form = AccountForm(request.POST) if acct_form.is_valid(): #create user username = acct_form.cleaned_data['username'] email = acct_form.cleaned_data['email'] password = acct_form.cleaned_data['password1'] user = User.objects.create_user(username, email, password) user.save() else: response = {} response['errors'] = acct_form.errors return JsonResponse(response, safe=False) return HttpResponse(status=200)
def index(request): if request.user.is_authenticated(): if request.user.user_profile.is_active: pwd_forms = ChangeForm() forms = AccountForm() tags = Tag.objects.all() template = loader.get_template('account.html') context = { "account": "active", "forms": forms, "tags": tags, "username": request.user.username, "pwd_forms": pwd_forms } return HttpResponse(template.render(context, request)) else: return HttpResponseRedirect('/notice/') else: return HttpResponseRedirect('/login/')
def account(): img = url_for('static', filename='profile_pics/' + current_user.image) form = AccountForm() if form.validate_on_submit(): if form.picture.data: random_hex = secrets.token_hex(8) _, p_ext = os.path.splitext(form.picture.data.filename) p_fn = random_hex + p_ext picture_path = os.path.join(app.root_path, 'static/profile_pics', p_fn) form.picture.data.save(picture_path) db.update_picture(p_fn, current_user.username) current_user.image = p_fn flash('Picture Successfully Updated', 'success') return redirect(url_for('account')) return render_template('account.html', title='Account', form=form, image_file=img)
def account(): form = AccountForm() if form.validate_on_submit(): # Update user picture if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file # Update user info current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash("Your account has been updated!", 'success') return redirect(url_for('account')) elif request.method == 'GET': # Prepopulate field with user info form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='images/' + current_user.image_file) return render_template('account.html', image_file=image_file, form=form)
def view_account(): account_id = request.args.get('id') q = request.args.get('q') if q is not None: return redirect(url_for('view_accounts', page=1, q=q)) form = AccountForm(request.form) if request.method == 'POST' and form.validate(): if form.id.data: account = orm.Account.query.get(int(form.id.data)) account.username = form.telephone.data account.name = form.telephone.data account.telephone = form.telephone.data account.role = 0 account.flag_telephone = 1 if form.flag_telephone.data else 0 account.checkcode = form.checkcode.data account.source = form.source.data account.dtcreate = form.dtcreate.data orm.db.session.commit() else: account = orm.Account(form.telephone.data, '1234', form.telephone.data, form.telephone.data, 0, 1 if form.flag_telephone.data else 0, '1234', form.source.data, form.dtcreate.data) orm.db.session.add(account) orm.db.session.commit() form.id.data = account.id return redirect(url_for('view_account')) elif request.method == 'GET' and account_id: form = logic.GetAccountFormById(account_id) logic.LoadBasePageInfo('修改用户', '输入并确定', form) else: logic.LoadBasePageInfo('新建用户', '输入并确定', form) if form.id.data: account = orm.Account.query.get(int(form.id.data)) form.account = account return render_template('view_account.html', form=form)
def transaction(id): is_trans_popop_active = "" transaction_form = CreditDebitForm(request.form) transaction_form.hdn_transaction_id.data = id transaction_form.FROM_ACCOUNT.choices = Account.get_account_by_type(1) # transaction_form.FROM_ACCOUNT.default = "1" transaction_form.TO_ACCOUNT.choices = Account.get_account_by_type(2) # transaction_form.TO_ACCOUNT.default = "1" # transaction_form.process() if id != 0 and request.method != "POST": db_transaction_account = Account.get_account_transaction(0, 0, id) transaction_form.TRANSACTION_COMMENTS.data = db_transaction_account[0][ "TRANSACTION_COMMENTS"] transaction_form.TRANSACTION_AMOUNT.data = db_transaction_account[0][ "TRANSACTION_AMOUNT"] transaction_form.FROM_ACCOUNT.process_data( db_transaction_account[0]["FROM_ACCOUNT_ID"]) transaction_form.TO_ACCOUNT.process_data( db_transaction_account[0]["TO_ACCOUNT_ID"]) transaction_form.hdn_transaction_id.data = db_transaction_account[0][ "TRANSACTION_ID"] is_trans_popop_active = "active" if request.method == "POST": if transaction_form.validate(): Account.save_transaction(transaction_form, id) return redirect(url_for("index", id=0)) else: is_trans_popop_active = "active" return render_template( "index.html", accounts=Account.get_accounts(0), account_transactions=Account.get_account_transaction(0, 0, 0), form=AccountForm(), form2=transaction_form, is_account_popup_active="", is_trans_popop_active=is_trans_popop_active, )
def index(id): is_account_popup_active = "" accounts_form = AccountForm(request.form) accounts_form.hdn_account_id.data = id if id != 0 and request.method != "POST": db_account = Account.get_accounts(id) accounts_form.hdn_account_id.data = db_account[0]["ID"] accounts_form.account_type.process_data(db_account[0]["TYPE"]) accounts_form.full_address.data = db_account[0][ "ACCOUNT_HOLDER_ADDRESS"] accounts_form.full_name.data = db_account[0]["NAME"] accounts_form.mobile.data = db_account[0][ "ACCOUNT_HOLDER_CONTACT_NUMBER"] accounts_form.account_number.data = db_account[0][ "ACCOUNT_HOLDER_BANK_DETAILS"] is_account_popup_active = "active" transaction_form = CreditDebitForm() transaction_form.FROM_ACCOUNT.choices = Account.get_account_by_type(1) transaction_form.TO_ACCOUNT.choices = Account.get_account_by_type(2) print(request.method) if request.method == "POST": if accounts_form.validate(): Account.create_account(accounts_form, id) return redirect(url_for("index", id=0)) else: is_account_popup_active = "active" return render_template( "index.html", accounts=Account.get_accounts(0), account_transactions=Account.get_account_transaction(0, 0, 0), form=accounts_form, form2=transaction_form, is_account_popup_active=is_account_popup_active, is_trans_popop_active="", )
def my_account(): user_info = General.query.get(current_user.id) form = AccountForm( name=user_info.name, email=user_info.email, password=None, api_key=user_info.api_key, ) if form.validate_on_submit(): message = "" if form.password.data: hash_pw = generate_password_hash(form.password.data, method="pbkdf2:sha256", salt_length=8) user_info.password = hash_pw message += "Password change has been saved." user_info.name = form.name.data user_info.email = form.email.data user_info.api_key = form.api_key.data message += " All changes saved." flash(message) db.session.commit() return redirect(url_for("account.my_account")) return render_template("account.html", form=form, api=user_info.api_key)
def edit_account(id): """ Edit an entry """ check_admin() add_account = False account = Account.query.get_or_404(id) form = AccountForm(obj=account) if form.validate_on_submit(): account.AccNum = form.AccNum.data account.name = form.name.data account.AccCategory = form.AccCategory.data account.SaccCategory = form.SaccCategory.data account.balance = form.balance.data account.Comment = form.Comment.data db.session.commit() flash('You have successfully edited the entry.') # redirect to the departments page return redirect(url_for('admin.list_account')) form.AccNum.data = account.AccNum form.name.data = account.name form.AccCategory.data = account.AccCategory form.SaccCategory.data = account.SaccCategory form.balance.data = account.balance form.Comment.data = account.Comment return render_template('admin/accounts/account.html', action="Edit", add_account=add_account, form=form, account=account, title="Edit Entry")