def channel_leave(channel_id): Account.leave_from_channel(channel_id, current_user.id) db.session().commit() return redirect( url_for("one_channel_index", channel_id=channel_id, sort='first'))
def account_create(): if request.method == "GET": return render_template("auth/new.html", accountform = AccountForm(), my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), public_channels=Channel.get_all_publics()) messages = [] messages.append("THESE ARE THE CONDITIONS YOU MUST PAST") messages.append("*username must be 2 character length") messages.append("*password must be 8 character length") messages.append("*motto must be 2 character length") messages.append("*email must be 6 character length and must be real email") accountform = AccountForm(request.form) password_wrong = "" not_same = False if not accountform.password.data == accountform.password2.data: password_wrong="Passwords must be same" not_same = True if not accountform.validate() or not_same == True: return render_template("frontpage.html", accountform = AccountForm(), error="somethin went wrong :(", pass_error = password_wrong, errors=messages) account = Account(accountform.username.data, accountform.password.data, accountform.motto.data, accountform.email.data) account.admin = False if current_user.is_authenticated: if request.form.get("super") == "True": account.admin = True db.session().add(account) db.session().commit() # this happens if admin is creating account if current_user.is_authenticated: return redirect(url_for("one_channel_index", channel_id=1, sort="first")) return redirect(url_for("auth_login"))
def group_home(param): group = Groups.query.filter_by(id=param).first() if not group: groups = Groups.find_usernames_for_group_owners() return render_template("index.html", groups=groups, error="That group does not exist") stat = GroupAccountLink.query.filter_by(account_id=current_user.get_id(), group_id=param).first() if not stat: s = False elif stat.get_status(): groups = Groups.find_usernames_for_group_owners() return render_template("index.html", groups=groups, error="You are banned from this group") else: s = True mem = Account.find_usernames_for_members(param) disc = Discussion.find_usernames_for_discussion_owners(param) return render_template("group/index.html", discussions=disc, target=param, status=s, members=mem, group_owner=group.owner_id)
def single_account_index(account_id): account = Account.query.get(account_id) return render_template("auth/index.html", account = account, accountform = AccountForm(), channels = Account.find_accounts_channels(account_id), my_channels=Channel.get_my_channels(account_id), all_channels=Channel.get_channels_where_not_in(account_id), public_channels=Channel.get_all_publics(), messages=Message.query.filter_by(account_id=account_id), comments=Comment.get_comment_message_and_channel_id(account_id))
def user_edit(): form = EditForm(request.form) groups = Groups.find_usernames_for_group_owners() if not form.validate(): e = "Minimum length for name and password is 3" return render_template("index.html", groups=groups, error=e) p1 = request.form.get("password_new1") p2 = request.form.get("password_new2") pold = request.form.get("password_old") old = Account.query.filter_by(id=current_user.get_id()).first() if old.password == pold: if p1 == p2: Account.change_password(p1, current_user.get_id()) return redirect(url_for("user_own")) else: e = "Your passwords do not match" else: e = "Your old password was wrong" return render_template("index.html", groups=groups, error=e)
def accounts_update(account_id): accountform = AccountForm(request.form) # check if username is whitespaces only char1 = False email = False not_same = False messages = [] messages.append("THESE ARE THE CONDITIONS YOU MUST PAST") messages.append("*username must be 2 character length") messages.append("*password must be 8 character length") messages.append("*motto must be 2 character length") messages.append("*email must be 6 character length and must be real email") # email check for c in accountform.email.data: if c == '@': char1 = True if char1 == True: if c == '.': email = True if not accountform.password.data == accountform.password2.data: messages.append("*password was not same") not_same = True if not accountform.validate() or email == False or accountform.username.data.isspace() or not_same == True: return render_template("auth/index.html", accountform = AccountForm(), errors = messages, account=current_user, my_channels=Channel.get_my_channels(current_user.id), all_channels=Channel.get_channels_where_not_in(current_user.id), channels=Account.find_accounts_channels(current_user.id), public_channels=Channel.get_all_publics(), messages=Message.query.filter_by(account_id=current_user.id), comments=Comment.get_comment_message_and_channel_id(current_user.id)) account = Account.query.get(account_id) account.username = accountform.username.data account.password = accountform.password.data account.motto = accountform.motto.data account.email = accountform.email.data db.session().commit() return redirect(url_for("single_account_index"))
def users_create(): old = Account.query.filter_by(name=request.form.get("username")).first() if old: return render_template("users/new.html", form=AccountForm(), error="That name is taken") form = AccountForm(request.form) if not form.validate(): return render_template( "users/new.html", form=AccountForm(), error="Minimum length for name and password is 3") u = Account(request.form.get("username"), request.form.get("password")) db.session().add(u) db.session().commit() return render_template("users/loginform.html", form=LoginForm(), error="Please login to complete signup")
def auth_register(): form = RegisterForm() if form.validate_on_submit(): user = db.session.query(Account).filter_by( name=form.register_name.data).first() if user: return render_template( "auth/loginform.html", form=LoginForm(), register_form=form, register_error="Account name is already taken") account_to_add = Account(form.register_name.data, form.register_password.data) db.session().add(account_to_add) db.session().commit() return redirect(url_for("auth_login")) else: return render_template("auth/loginform.html", form=LoginForm(), register_form=form)
def campaigns_list(): joined_campaigns=db.session.query(Campaign).filter(Campaign.accounts.contains(current_user)) number_of_joined_campaigns=Account.number_of_joined_campaigns(current_user.id) return render_template("campaigns/list.html", joined_campaigns=joined_campaigns, number_of_joined_campaigns=number_of_joined_campaigns)