Пример #1
0
    def register(self, form):
        username = form.getvalue("username", "")
        password = form.getvalue("password", "")
        realname = form.getvalue("realname", "")
        email = form.getvalue("email", "")
        log("New account request as: " + username)

        status = "ok"
        message = ""
        if len(username) < 6:
            status = "fail"
            message = "Invalid username"
            log("Username was wrong.")
        elif len(realname) < 6:
            status = "fail"
            message = "Invalid real name"
            log("Username was wrong.")
        elif re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email) == None:
            status = "fail"
            message = "Invalid email address"
            log("E-mail was wrong.")

        if status == "ok":
            try:
                user = User(username, password, email, realname)
                user.save()
                log("Registration ended with status: " + status)
            except Exception, e:
                status = "fail"
                message = "Server error"
                log("DB ERROR: " + str(e))
Пример #2
0
def register():

    form = SignupForm()

    try:
        if form.validate_on_submit():
            existing_user = User.query.filter_by(email=form.email.data).first()
            if existing_user is None:
                user = User(name=form.name.data, email=form.email.data)
                user.set_password(form.password.data)
                db.session.add(user)
                db.session.commit()
                return redirect("/admin")
            else:
                flash('A user already exists with that email address.')
    except SQLAlchemyError as e:
        error = str(e.__dict__['orig'])
        print(error)
        flash('Database error.')

    return render_template('register.html', form=form)
Пример #3
0
    def recover(self, form):
        email = form.getvalue("email", "")
        log("Reset password for {0}.".format(email))

        status = "ok"
        try:
            user = User.get_by_email(email)
            if user:
                status = "ok"
            else:
                status = "fail"
        except Exception, e:
            status = "fail"
            log("DB ERROR: " + str(e))
Пример #4
0
    def signin(self, form):
        username = form.getvalue("username", "")
        password = form.getvalue("password", "")
        log("Signin in as {0}.".format(username))

        status = "ok"
        message = ""
        sessionkey = ""
        realname = ""
        try:
            user = User.auth(username, password)
            if user:
                log("User was succesfully authenticated: {0}".format(username))
                sessionkey = "111"
                realname = user.real_name
                message = Message.get_latest().message
            else:
                log("Invalid username or password for: {0}".format(username))
                status = "fail"
                message = "Invalid username or password"
        except Exception, e:
            log("DB ERROR: " + str(e))
            status = "fail"