Exemple #1
0
def login():
    form = LoginForm2()
    if form.validate_on_submit():
        if session.get('image').lower() != form.verify_code.data.lower():
            flash('Identify code error')
            return render_template('auth/login.html', form=form)
        _user = mydb.user_get()
        o1 = _user.find_by_email(form.email.data)
        user = User()
        user.id = _user.uid
        user.confirmed = _user.confirm
        user.email = _user.email
        user.password = _user.password
        user.username = _user.name
        user.privilege = _user.privilege
        if o1 and user.verify_password(form.password.data):
            # user = User.query.filter_by(email=form.email.data).first()
            # if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            next = request.args.get('next')
            if next is None or not next.startswith('/'):
                next = url_for('main.index')
            return redirect(next)
        flash('Invalid username or password.')
    return render_template('auth/login.html', form=form)
Exemple #2
0
def edit_profile_admin(id):
    form = EditProfileAdminForm()
    _user = mydb.user_get()
    _user.find(id)
    user = User()
    gz(user, _user)
    print(form.privilege.data)
    # print(form.validate_on_submit())
    if request.method == "POST":
        print(form.email.data)
        print("!!!")
        _user.email = form.email.data
        _user.name = form.name.data
        _user.password = form.password.data
        if _user.privilege == 2 and int(form.privilege.data) == 2:
            flash("The guy is adminstrator!")
            return redirect(url_for('.edit_profile_admin', id=id))
        _user.privilege = int(form.privilege.data)
        _user.modify()
        flash('The profile has been updated.')
        return redirect(url_for('.edit_profile_admin', id=id))
    form.uid.data = user.id
    form.email.data = user.email
    form.privilege.data = user.privilege
    form.name.data = user.username
    return render_template('main/edit_profile.html', form=form)
Exemple #3
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        # user = User(email=form.email.data,
        #             username=form.username.data,
        #             password=form.password.data)
        user = User()
        user.email = form.email.data
        user.username = form.username.data
        user.password = form.password.data

        _user = mydb.user_get()
        # print(_user.find_by_email(user.email))
        _user.email = user.email
        _user.password = (user.password)
        _user.name = user.username
        _user.confirm = 0
        _user.add_user()
        # print(_user.find_by_email(user.email))
        # db.session.add(user)
        # db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email,
                   'Confirm Your Account',
                   'auth/email/confirm',
                   user=user,
                   token=token)
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Exemple #4
0
 def validate_uid(self, field):
     a = mydb.user_get()
     if field.data <= 2018:
         raise ValidationError('Id is illegal')
     if not a.find(field.data):
         # if field.data != self.user.email and \
         #         User.query.filter_by(email=field.data).first():
         raise ValidationError("Id doesn't exisit.")
Exemple #5
0
def user(useremail):
    _user = mydb.user_get()
    _user.find_by_email(useremail)
    user = User()
    gz(user, _user)
    # user.email = _user.email
    # user.id = _user.uid
    # user.
    # user = User.query.filter_by(username=username).first_or_404()
    return render_template('main/user.html', user=user)
Exemple #6
0
def load_user(user_id):
    _user = mydb.user_get()
    _user.find(int(user_id))
    user = User()
    user.confirmed = _user.confirm
    user.privilege = _user.privilege
    user.id = _user.uid
    user.phone = _user.phone
    user.password = _user.password
    user.username = _user.name
    user.email = _user.email
    if user.email == '':
        return None
    print("skjskdjksjd:", user.email)
    return user
Exemple #7
0
def confirm(token):
    if current_user.confirmed:
        return redirect(url_for('main.index'))
    if current_user.confirm(token):
        # print("this:",current_user.confirmed, current_user)
        _user = mydb.user_get()
        _user.find_by_email(current_user.email)
        _user.privilege = 1
        _user.modify()
        _user.find_by_email(current_user.email)
        # print("confirm",_user.confirm)
        # db.session.commit()
        flash('You have confirmed your account. Thanks!')
    else:
        flash('The confirmation link is invalid or has expired.')
    return redirect(url_for('main.index'))
Exemple #8
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            _user = mydb.user_get()
            _user.find_by_email(current_user.email)
            _user.password = form.password.data
            _user.modify()
            logout_user()
            # current_user.password = form.password.data
            # db.session.add(current_user)
            # db.session.commit()
            flash('Your password has been updated.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Exemple #9
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        _user = mydb.user_get()
        _user.find(current_user.id)
        _user.name = form.name.data
        _user.phone = form.phone.data
        _user.modify()
        # current_user.name = form.name.data
        # current_user.location = form.location.data
        # current_user.about_me = form.about_me.data
        # db.session.add(current_user._get_current_object())
        # db.session.commit()
        flash('Your profile has been updated.')
        return redirect(url_for('.user', useremail=current_user.email))
    form.name.data = current_user.username
    form.phone.data = current_user.phone
    # form.location.data = current_user.location
    # form.about_me.data = current_user.about_me
    return render_template('main/edit_profile.html', form=form)
Exemple #10
0
 def validate_email(self, field):
     _user = mydb.user_get()
     if _user.find_by_email(field.data):
         # if User.query.filter_by(email=field.data).first():
         raise ValidationError('Email already registered.')
Exemple #11
0
 def validate_email(self, field):
     _user = mydb.user_get()
     if _user.find_by_email(field.data):
         raise ValidationError('Email already registered.')