コード例 #1
0
ファイル: login.py プロジェクト: Intern666/Goocat_intern
def regist():
    """
    注册函数,检测,返回用户名,email,密码
    :return:
    """
    if request.method == 'GET':
        return render_template('regist.html')
    else:
        email = request.form.get('email')
        username = request.form.get('username')
        password1 = request.form.get('password1')
        password2 = request.form.get('password2')
        if email == '' or username == '' or password1 == '' or password2 == '':
            return render_template('regist.html', error='输入有误,请重新输入!')
        user = dbhelper.fetch_user_by_email(email)
        # 手机号码验证,如果被注册了就不能用了
        if user:
            return render_template('regist.html', error_email='该邮箱被注册,请更换邮箱!')
        else:
            # password1 要和password2相等才可以
            if password1 != password2:
                return render_template('regist.html',
                                       eassword='两次密码不相等,请核实后再填写')
            else:
                dbhelper.insert_user(email, username, password1)
                flash("注册成功!")
                return redirect(url_for('login.login'))
コード例 #2
0
def register():
    if 'username' in session:
        flash('You cannot register while you are logged in, please log out first.')
        return redirect(url_for('home'))

    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        username_exist = db.retrieve_user_by_username(form.username.data)
        email_exist = db.retrieve_user_by_email(form.email.data)

        if username_exist:
            form.username.errors.append('Username already taken')

        if email_exist:
            form.email.errors.append('Email already used')

        if username_exist or email_exist:
            return render_template('register.html',
                                   form=form,
                                   title='Sign Up')

        #  load data from form and create User object
        user = User(form.username.data,
                    form.email.data,
                    User.generate_hash(form.password.data),
                    form.acc_type.data)

        #  save user to database
        db.insert_user(user)

        #  generate 5 digits activation code and save it inside db
        activation_code = str(random.randint(10000, 99999))
        db.insert_token(user.username, activation_code)

        #  generate activation link, activation code is encoded as URL parameter
        activation_link = url_for('activate', _external=True, username=user.username)
        activation_link += "?activation_code=" + activation_code

        #  generate template for confirmation email
        email_msg = render_template('email/verify_email.html',
                                    username=user.username,
                                    activation_code=activation_code,
                                    activation_link=activation_link)

        #  send email
        send_email(recipient=user.email, subject='Account Activation', template=email_msg)

        flash('Thanks for registering, check your email inbox for instructions on how to activate your account')
        return redirect(url_for('home'))

    return render_template('register.html',
                           form=form,
                           title='Sign Up')
コード例 #3
0
    if num > 1:
        for i in range(2, num):
            content = zhihu.fetch_people_page(conn, username, i)
            if content is None:
                continue
            link_list = zhihu.get_answer_link_list(content)
            zhihu.saveAnswer(conn, username, link_list, dblock)
    with dblock:
        dbhelper.update_user_by_name(username, {'fetch': dbhelper.FETCH_OK})
    conn.close()
    zhihu.slog('### after saveAnswer ###')
    s.release()

if len(sys.argv) > 1:
    username = sys.argv[1]
    dbhelper.insert_user({'name': username, 'fetch': dbhelper.FETCH_ING})
    fetch_proc(username)
else:
    threads = []
    while True:
        i = threading.active_count()
        print('active_count', i)
        with dblock:
            username = dbhelper.getNotFetchedUserName()
        if username is None:
            print('finish')
            break
        s.acquire()
        t = threading.Thread(target=fetch_proc, args=(username,))
        threads.append(t)
        t.start()