當前位置: 首頁>>代碼示例>>Python>>正文


Python User.email方法代碼示例

本文整理匯總了Python中model.User.email方法的典型用法代碼示例。如果您正苦於以下問題:Python User.email方法的具體用法?Python User.email怎麽用?Python User.email使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在model.User的用法示例。


在下文中一共展示了User.email方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process_login

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def process_login():
    """Log in existing users and redirect to homepage."""

    email = request.form.get('email')
    password = request.form.get('password')

    # select the user from the database who has the given email (if any)
    user = User.query.filter(User.email==email).first()

    if user:
        # if user in database, check that password is correct
        if password == user.password:
            session['user'] = user.user_id
            session['waypoints'] = []

            flash("You're logged in.")
            return redirect('/')

        else:            
            flash('Your password is incorrect. Please enter your information again or register as a new user.')
            return redirect('/login')

    else:
        flash('Please register as a new user.')
        return redirect('register.html') 
開發者ID:cvlong,項目名稱:sfparks,代碼行數:27,代碼來源:server.py

示例2: process_registration

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def process_registration():
    """Add new user to database and log them in."""

    email = request.form.get('email')
    password = request.form.get('password')

    # instantiate a user object with the information provided
    new_user = User(email=email, 
                    password=password)
    
    # add user to db session and commit to db
    db.session.add(new_user)
    db.session.commit()

    # add user to the session; redirect to homepage
    session['user'] = new_user.user_id
    session['waypoints'] = []
    
    flash("You're logged in.")
    return redirect('/') 
開發者ID:cvlong,項目名稱:sfparks,代碼行數:22,代碼來源:server.py

示例3: signup_process

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def signup_process():
    """Process signup form"""

    email = request.form["email"]
    password = request.form["password"]
    first_name = request.form["firstname"]
    last_name = request.form["lastname"]
    foo = request.form
    print "*********"
    print "foo: "
    print "type: ", type(foo)
    print "keys: ", foo.keys()

    new_user = User(email=email, password=password, first_name=first_name, last_name=last_name)
    db.session.add(new_user)
    db.session.commit()

    session["user_id"] = new_user.user_id
    flash("User %s added." % email)
    flash("Logged in")
    return redirect("/") 
開發者ID:AnliYang,項目名稱:bobafetch,代碼行數:23,代碼來源:server.py

示例4: login_process

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def login_process():
    """Process login."""

    email = request.form["email"]
    password = request.form["password"]

    user = User.query.filter(User.email==email).first()

    if not user:
        flash("No such user")
        return redirect("/login")

    if user.password != password:
        flash("Incorrect password")
        return redirect("/login")

    session["user_id"] = user.user_id
    flash("Logged in")
    return redirect("/") 
開發者ID:AnliYang,項目名稱:bobafetch,代碼行數:21,代碼來源:server.py

示例5: sign_in

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def sign_in():
    res = {}
    if request.method == 'POST':
        req_data = json.loads(request.data)
        db_session = db.Session()
        result = db_session.query(User).filter(or_(User.username == req_data['username']\
            , User.email == req_data['username'])).first()
        if result is None:
            res['code'] = '0x7'
            res['message'] = 'Username not found.'
        else:
            passcode = hashlib.md5(req_data['password'] + result.salt).hexdigest()
            if result.password == passcode:
                session['is_login'] = True
                user_profile = {}
                user_profile['id'] = result.id;
                user_profile['username'] = result.username
                user_profile['password'] = result.password
                session['user_profile'] = json.dumps(user_profile)
                instances = db_session.query(Instance).all()
                res['code'] = '0x1'
                res['message'] = 'sign in successful'
            else:
                res['code'] = '0x6'
                res['message'] = 'wrong password.'
        return jsonify(**res)
    return render_template('index.html') 
開發者ID:saga92,項目名稱:eagle,代碼行數:29,代碼來源:user.py

示例6: sign_up

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def sign_up():
    res = {}
    if request.method == 'POST':
        eagle_logger.debug(type(request.data))
        req_data = json.loads(request.data)
        db_session = db.Session()
        result = db_session.query(User).filter(User.username == req_data['username']).first()
        req_email =  req_data.get('email', None)
        if req_email is not None:
            result_mail = db_session.query(User).filter(User.email == req_email).first()
        if result is not None:
            res['code'] = '0x4'
            res['message'] = 'Username have been occupied by others'
        elif req_email is not None and result_mail is not None:
            res['code'] = '0x5'
            res['message'] = 'Email has been occupied by others'
        else:
            timestamp = str(time.time()) + str(random.randint(10000, 20000))
            salt = hashlib.md5(timestamp).hexdigest()
            passcode = hashlib.md5(req_data['password'] + salt).hexdigest()
            u = User(req_data['username'], passcode, email=req_data.get('email', ''), \
                salt=salt, create_time=datetime.datetime.now(), update_time=datetime.datetime.now())
            db_session.add(u)
            db_session.commit()
            res['code'] = '0x1'
            res['message'] = 'sign up successful'
        return jsonify(**res)
    return render_template('index.html') 
開發者ID:saga92,項目名稱:eagle,代碼行數:30,代碼來源:user.py

示例7: profile

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def profile():
    res={}
    res['code'] = '0x1'
    res['message'] = 'modify profile successful'
    if request.method == 'POST':
        eagle_logger.debug(type(request.data))
        req_data = json.loads(request.data)
        db_session = db.Session()
        testid = req_data['id']
        result = db_session.query(User).filter(User.id == testid).first()
        req_id = result.id
        new_username = req_data['username']
        if new_username is not None:
            db_session = db.Session()
            result_User = db_session.query(User).filter(User.username == new_username).first()
            if result_User is not None and req_id != result_User.id:
                res['code'] = '0x4'
                res['message'] = 'Username has been occupied by others'
                return jsonify(**res)
            else:
                update_username_by_id(req_id, new_username)
        new_email = req_data['email']
        if new_email is not None:
            db_session = db.Session()
            result_User = db_session.query(User).filter(User.email == new_email).first()                   
            if result_User is not None and req_id != result_User.id:
                res['code'] = '0x5'
                res['message'] = 'Email has been occupied by others'
                return jsonify(**res)
            else:
                update_email_by_id(req_id, new_email)
        new_password = req_data['password']
        if new_password is not None:
            timestamp = str(time.time()) + str(random.randint(10000, 20000))
            salt = hashlib.md5(timestamp).hexdigest()
            passcode = hashlib.md5(new_password + salt).hexdigest()
            update_password_by_id(req_id, passcode)
            update_salt_by_id(req_id, salt)
        update_update_time_by_id(req_id, datetime.datetime.now())
        return jsonify(**res)
    return render_template('index.html') 
開發者ID:saga92,項目名稱:eagle,代碼行數:43,代碼來源:user.py

示例8: login

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def login():
    """Login page."""
    if request.method == 'POST':
        email = request.form.get('email')
        password = request.form.get('password')
        user = User.query.filter(User.email == email, User.password == password).first()
        if user is not None:
            session['user_id'] =  user.user_id
            return redirect(url_for('recommendations'))
        else:
            flash("Wrong username or password! Please try again, or go to sign up page to create new account.")

    return render_template('login.html') 
開發者ID:EmmaOnThursday,項目名稱:next-book,代碼行數:15,代碼來源:__init__.py

示例9: sign_up

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def sign_up():
    """For new users only: sign-up page."""

    if request.method == 'POST':
        f_name = request.form.get('f_name')
        l_name = request.form.get('l_name')
        email = request.form.get('email')
        password  = request.form.get('password')
        goodreads_uid = int(request.form.get('goodreads_uid'))
        rec_frequency = 1
        user_id = 1

        user = User.query.filter(User.email == email).all()

        if user != []:
            flash("Looks like you've already signed up! Please log in.")
            return redirect(url_for('index'))

        else:
            new_user = User(email=email, password=password,
                f_name=f_name, l_name=l_name,
                goodreads_uid=goodreads_uid, rec_frequency=rec_frequency,
                sign_up_date=dt.datetime.now(), paused=0, user_id=user_id)
            db.session.add(new_user)
            db.session.commit()
            flash("Welcome to NextBook!")
            session['current_user_id'] = new_user.user_id

            ## new user setup ###
            q = Queue(connection=Redis())

            results = q.enqueue_call(new_user_full_setup,
                args = [gr_user_id, new_user.user_id, goodreads_key],
                ttl=86400)

            session['new_user_job_id'] = results.get_id()

            return redirect(url_for('recommendations'))

    return render_template('sign-up.html') 
開發者ID:EmmaOnThursday,項目名稱:next-book,代碼行數:42,代碼來源:__init__.py

示例10: profile_edit

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def profile_edit():
    """ Edit profile information """

    # Set the value of the user id of the user in the session
    id = session.get('id')

    # Query the database for the user
    user_info = User.query.filter_by(id=id).first()

    # Get information from the forms
    name = request.form.get("profile-name")
    email = request.form.get("profile-email")
    password = request.form.get("new-password")

    # Replace info in the database with new info
    if name:
        user_info.name = name
        db.session.commit()

    if password:
        user_info.password = password
        db.session.commit()

    if email:
        user_info.email = email
        db.session.commit()

    name_info = {
        'name': name,
        'email': email
    }

    # Return jsonified budget info to submit-new-account-info.js
    return jsonify(name_info) 
開發者ID:emilydowgialo,項目名稱:Spent,代碼行數:36,代碼來源:server.py

示例11: sign_up

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def sign_up():
    """ Sign up form consumption """

    # Gathering information from the sign up form
    name = request.form.get("name")
    email = request.form.get("email")
    password = request.form.get("password")

    # If the user does not exist, this will return None, and we will add them
    # to the database, otherwise we will flash an error message
    email_login_query = User.query.filter_by(email=email).first()

    # Check if user already exists
    if email_login_query is None:

        # If the user does not exist in the database, we add the user
        new_user = User()

        # Set the new user's name, email, and password
        new_user.name = name
        new_user.email = email
        new_user.password = password

        # Add the new user to the session - this is a database insertion
        db.session.add(new_user)
        db.session.commit()

        # Flash a message confirming the user has successfully signed up
        flash('You have successfully signed up')

        return redirect(url_for('index'))

    # Should the user already exist in the database, this will
    # redirect them back to the homepage and flash a message that says
    # a user with that information already exists
    else:
        user_existence_check = User.query.filter(
                                                and_(
                                                    User.email == email,
                                                    User.password == password)).first()

        if user_existence_check:

            # Flash a message saying a user by this name already exists
            flash('A user by this name already exists')

            # Take the user back to the homepage
            return redirect(url_for("index")) 
開發者ID:emilydowgialo,項目名稱:Spent,代碼行數:50,代碼來源:server.py

示例12: login_form

# 需要導入模塊: from model import User [as 別名]
# 或者: from model.User import email [as 別名]
def login_form():
    """ Login form """

    # FIXME: login breaks if incorrect email but correct password
    # login works with incorrect password

    # Gather information from the login form
    email = request.form.get("email")
    password = request.form.get("password")

    # If either of these return None, the user will not be able to
    # successfully log in
    email_login_query = User.query.filter_by(email=email).first()
    password_login_query = User.query.filter_by(password=password).first()

    # Check if email_login_query is empty
    if email_login_query is None and password_login_query is None:

        # Flash an error message if the login information provided by the user
        # does not match any records
        flash('Error in logging in')

        # Take the user back to the homepage so they can try logging in again
        # or sign up if they haven't
        return redirect(url_for("index"))

    # If the user logs in with the incorrect email an error message will flash
    # and they will not be logged in
    elif email_login_query is None:

        flash('Error in logging in')

        return redirect(url_for("index"))

    # If the user logs in with the incorrect password an error message will flash
    # and they will not be logged in
    elif password_login_query is None:

        flash('Error in logging in')

        return redirect(url_for("index"))

    else:
        # Put the id into the session
        session['id'] = email_login_query.id

        # Take the user to the dashboard page, using their id
        return redirect(url_for('dashboard', id=session['id'])) 
開發者ID:emilydowgialo,項目名稱:Spent,代碼行數:50,代碼來源:server.py


注:本文中的model.User.email方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。