def edit_user(): user = UserAccess().the_current_user() form = EditUserForm(user) if request.method == 'POST' and form.validate_on_submit(): UserAccess(_obj=user).edit_model_object( username=form.username.data.strip(), about=form.about.data.strip()) flash('Your changes have been saved.') return redirect(url_for('profile')) elif request.method == 'GET': form.username.data = user.username form.email.data = user.email form.about.data = user.about return render_template('edit_user.html', title='Edit User', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): user = UserAccess(username=form.username_or_email.data, email=form.username_or_email.data). \ user_by_username_or_email() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)
def profile(): the_user = UserAccess().the_current_user() admins = AdminAccess().admins_of_current_user() employees = EmployeeAccess().employees_of_current_user() clients = ClientAccess().clients_of_current_user() admins_pending = AdminAccess().admins_pending_of_current_user() employees_pending = EmployeeAccess().employees_pending_of_current_user() return render_template('profile.html', user=the_user, admins=admins, employees=employees, clients=clients, admins_pending=admins_pending, employees_pending=employees_pending)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = UserAccess(username=form.username.data.strip(), email=form.email.data, password=form.password.data).create_user() if user: flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) else: flash('Something went wrong!') return render_template('register.html', title='Register', form=form)
def remove_user(): obj = UserAccess().the_current_user_of_model() return remove_object(obj=obj)
def validate_email(self, email): if email.data.strip().lower() != self.user.email.lower(): users = UserAccess(email=self.email.data.strip()).users_by_email() if users is not None: raise ValidationError('Please use a different Email.')
def validate_username(self, username): if username.data.lower() != self.user.username_or_email.lower(): user = UserAccess(username=self.username.data.strip()). \ users_by_username() if user is not None: raise ValidationError('Please use a different username.')
def validate_username(self, username): user = UserAccess(username=username.data.strip()). \ users_by_username() if user is not None: raise ValidationError('Please use a different username.')