当前位置: 首页>>代码示例>>Python>>正文


Python User.set_password方法代码示例

本文整理汇总了Python中model.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.User的用法示例。


在下文中一共展示了User.set_password方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
 def post(self, error_msg=None):
     email = self.request.get("email")
     username = self.request.get("username")
     users = User.all().filter('email', email)
     user = User()
     user.email = email
     user.username = username
     user.fullname = self.request.get("firstname")+" "+self.request.get("lastname")
     user.birthday = datetime.datetime.strptime(self.request.get("birthday"), '%Y-%m-%d')
     user.set_password(self.request.get("password")) #set password. need encrypt. 
     user.firstname = self.request.get("firstname")
     user.lastname = self.request.get("lastname")
     user.country = self.request.get("country")
     gender = self.request.get("gender")
     if gender:
         gender_ = str(gender)[0:1]
         user.gender = gender_
     if users.count() == 0:
         user.put()
         #init() the session
         sessions.Session().login_user(user)
         self.redirect("/")
         return
     else:
         error_msg = "That email address has already been registered."
     template_values = {
        "temp_user": user,
        "error": error_msg
     }
     self.generate('signup.html',template_values)
开发者ID:Git-Host,项目名称:cpedialog,代码行数:32,代码来源:login.py

示例2: create_tables

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def create_tables():
    Base.metadata.create_all(engine)
    u = User(email='[email protected]', username='steph')
    u.set_password('unicorn')
    session.add(u)
    u2 = User(email='[email protected]', username='stroud')
    u2.set_password('unicorn')
    session.add(u2)
    b = Book(
        title='The Book of Steph',
        amazon_url='www.smstroud.com',
        owner_id=1
    )
    session.add(b)
    b2 = Book(
        title='Stroud\'s Story',
        amazon_url='www.smstroud.com',
        owner_id=1,
        current_borrower=2
    )
    b_h = BorrowHistory(book_id=2, borrower_id=2, date_borrowed=datetime.now)
    # p = Post(title='test post', body='body of a test post.')
    # u.posts.append(p)
    session.add(b)
    session.add(b2)
    b2.borrow_history.append(b_h)
    session.commit()
开发者ID:stroud109,项目名称:medusa,代码行数:29,代码来源:db_create.py

示例3: make_account

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def make_account():
    username = request.form.get("username")
    email = request.form.get("email")
    password = request.form.get("password")
    new_user = User(username=username, email=email)
    new_user.set_password(password=password)

    model.session.add(new_user)
    model.session.commit()
    model.session.refresh(new_user)
    return redirect(url_for("index"))
开发者ID:zardra,项目名称:Todo,代码行数:13,代码来源:views.py

示例4: new_user_reg

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def new_user_reg():

    email = request.form.get("email")
    password = request.form.get("password")
    password_ver = request.form.get("password_ver")
    firstname = request.form.get("firstname")
    surname = request.form.get("surname")
    address1 = request.form.get("address1")
    address2 = request.form.get("address2")
    city = request.form.get("city")
    state = request.form.get("state")
    zipcode = int(request.form.get("zipcode")) if request.form.get("zipcode") else None
    country = request.form.get("country")
    phone = int(request.form.get("phone")) if request.form.get("phone") else None
    
#Verification if user already exists
    existing = User.query.filter_by(email=email).first()

    if existing:
        flash("This email already exists,Please select another one!")
        return redirect(url_for("new_user_reg")) #redirect back to sign up page
    elif password != password_ver:
        flash("Your password do not match")
        return redirect(url_for("new_user_reg")) #redirect back to sign up page
    else:
        new_user = User(email=email, firstname = firstname, surname = surname)#make the new_user object
        new_user.set_password(password)

        # Queue it up to be put into the database
        model.session.add(new_user)

        # create a variable to use for input into the addresses table and geocoding
        a = Address(    email = email, 
                        address1 = address1, 
                        address2 = address2,
                        city = city,
                        state = state,
                        zipcode = zipcode,
                        country = country,
                        phone = phone)
        #get LagLng from google api for address input by user in this session
        a.geocode()
        # append address info including latlng of the new user to the adresses table
        new_user.addresses.append(a)

        # Now we've got all the stuff the database wants to put in the addresses table,
        # we can add and commit everything to the database.
        model.session.commit()

        login_user(new_user)
        
        return redirect(url_for("view_order", duck=request.args.get("duck")))
开发者ID:cathylouie,项目名称:Drone_Delivery,代码行数:54,代码来源:views.py

示例5: signup

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def signup():
    form = SignupForm()

    if form.validate_on_submit():
        user = User(email=form.email.data.lower(), created_at=datetime.datetime.now())
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        session['user_id'] = user.id
        session['email'] = user.email
        return redirect(url_for('index'))

    elif form.errors:
        flash("Error creating account")

    return render_template("signup.html", form=form)
开发者ID:danafallon,项目名称:IntonationCoach,代码行数:19,代码来源:application.py

示例6: add_reason

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def add_reason():
    """add user and language desired to dbsession and redirect to profile.html"""
    reason = request.form.get("reason")
    session['reason']=reason

    usr = User(
                name=session["name"], 
                email=session["email"],
                country_code=session["country_code"],
                mother_tongue_code=session["mother_tongue_code"],
                reason=session['reason'],
                age= '',
                sex= '',
                occupation='',
                current_city='',
                current_country='',
                origin_city='',
                origin_country='',
                about_txt='',
                profile_url=''
                )

    usr.set_password(session['password'])

    dbsession.add(usr)
    dbsession.commit()

    lang = dbsession.query(Language).filter_by(language_name=session.get('language')).first()

    lang_desired = Language_desired(
                user_id=usr.id,
                language_code = lang.language_code,
                level = session['level']     
                )

    dbsession.add(lang_desired)
    dbsession.commit()

    #clear session to get rid of superfluous info
    session.clear()
    #add info to session 
    session["login"] = usr.name
    session["mother_tongue"] = usr.language.language_name
    return redirect("/profile") 
开发者ID:amitch23,项目名称:Babel_Chat,代码行数:46,代码来源:babel.py

示例7: authenticate

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def authenticate():
    if request.form['btn'] == "login": 
        form_login = forms.LoginForm(request.form)
        if not form_login.validate():
            flash("Incorrect username or password") 
            return render_template("create_info")

        email = form_login.email.data
        password = form_login.password.data

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

        if not user or not user.authenticate(password):
            flash("Incorrect username or password")         
            return render_template("login.html")

        login_user(user)
        session["user_id"] = user.id
        return redirect(request.args.get("next", url_for("browse")))

    elif request.form['btn'] == "register": 
        password = request.form.get("password")
        email = request.form.get("email")
        first_name=request.form.get("first_name")
        last_name=request.form.get("last_name")
        new_user = User(email=email)
        new_user.set_password(password=password)
        new_user.first_name=first_name
        new_user.last_name=last_name
        model.session.add(new_user)
        model.session.commit()

        return redirect(url_for("create_info"))

    elif request.form['btn'] == "fb_login":
        fb_name = request.form.get("name")
        if current_user.is_anonymous == False:
            current_user.fb_id = fb_id
            current_user.fb_img_url = "https://graph.facebook.com/%s/picture?type=small" % fb_id 
            print current_user.fb_img_url 
            model.session.commit()
            model.session.refresh()
        return redirect(url_for("browse"))
开发者ID:dslevi,项目名称:CS-Go,代码行数:45,代码来源:controller.py

示例8: registerUser

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def registerUser():
    email = request.form.get('email')
    password = request.form.get('password')
    first_name = request.form.get('first_name')
    last_name = request.form.get('last_name')
    verify = request.form.get('verify')
    if User.query.filter_by(email=email).all():
        flash("Email already exists")
        return redirect(url_for("register"))
    if password != verify:
        flash("Passwords do not match")
        return redirect(url_for("register"))
    #creates user row and also starter tasks
    user = User(email=email, first_name=first_name, last_name=last_name)
    user.set_password(password)
    model.session.add(user)
    model.session.commit()
    # model.createUser(email, password)
    return redirect(url_for("login"))
开发者ID:nsamsami,项目名称:Arts,代码行数:21,代码来源:controller.py

示例9: register_process

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def register_process():
    """Process registration."""

    # Get form variables
    email = request.form.get("email")
    password = request.form.get("password")
    first_name = request.form.get("first_name")
    last_name = request.form.get("last_name")
    lang_id = request.form.get("lang_id")
    phone_number = request.form.get("phone")


    new_user = User(email=email, first_name=first_name,
                    last_name=last_name, lang_id=lang_id, phone_number=phone_number)

    new_user.set_password(password)
    db.session.add(new_user)
    db.session.commit()

    return redirect("/") 
开发者ID:nmalika5,项目名称:BreakingBarriers,代码行数:22,代码来源:server.py

示例10: create_account

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def create_account():
    '''
    This function uses form validation.
    '''

    form = forms.NewUserForm(request.form)
    if not form.validate():
        flash('Error, all fields are required')
        return render_template('register.html', form=form)

    email = form.email.data
    username = form.username.data
    username_or_email = or_(User.email == email, User.username == username)
    user = User.query.filter(username_or_email).first()

    if user:
        if user.email == email:
            form.email.errors = ['There\'s already an account with this email']
        if user.username == username:
            form.username.errors = ['There\'s aleady an account with this username']
        return render_template('register.html', form=form)

    new_user = User(
        username=username,
        email=email,
        avatar_url=AVATAR_URLS[6],
    )
    new_user.set_password(request.form.get('password'))

    model.session.add(new_user)

    model.session.commit()
    model.session.refresh(new_user)
    login_user(new_user)

    flash('You\'ve successfully created an account. Welcome!')
    return redirect(url_for('edit_user', id=new_user.id))
开发者ID:stroud109,项目名称:medusa,代码行数:39,代码来源:views.py

示例11: create_user

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def create_user():
    form = forms.RegisterForm(request.form)
    print "form variable!"
    if not form.validate():
        flash("username not valid")
        return render_template("register.html")

    first_name=form.first_name.data
    last_name=form.last_name.data
    email=form.email.data
    password=form.password.data

    existing = User.query.filter_by(email=email).first()
    if existing:
        flash("username already taken")
    else:
        user = User(email=email, first_name=first_name, last_name=last_name, password=password, salt="random")
        user.set_password(password)

        model.session.add(user)
        model.session.commit()
        login_user(user)

    return redirect(url_for("index"))
开发者ID:ebalcomb,项目名称:Flashcards,代码行数:26,代码来源:views.py

示例12: create_user

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def create_user():
	form = forms.RegisterForm(request.form)

	if not form.validate():
      	flash("All fields must be filled!")
      	return render_template("signup.html")

	first_name=form.first_name.data
	last_name=form.last_name.data
	email=form.email.data
	password=form.password.data

	existing = User.query.filter_by(email=email).first()
	if existing:
      	flash("Email is already registered!")
	else:
      	user = User(email=email, first_name=first_name, last_name=last_name, password=password, salt="random")
      	user.set_password(password)

      	model.session.add(user)
      	model.session.commit()
      	login_user(user)

	return url_for("index")

@app.route("/about"):
def about():
	return render_template("about.html")

@app.route("/contact")
def contact():
	return render_template("contact.html")



@app.route("/new_trip", methods=["POST"])
@login_required
def create_trip():
	form = forms.NewTripForm(request.form)
	if not form.validate():
		flash("Error, all fields are required.")
	else:
		start_date = form.start_date.data.datetime.strftime('%d-%m-%Y')
		end_date = form.end_date.data.datetime.strptime('%d-%m-%Y')
		days_delta = end_date - start_date
		total_days = days_delta.days + 1

		trip = Trip(title=form.title.data, destination=form.destination.data, start_date=start_date, end_date=end_date, total_days=total_days)
		model.session.add(trip)
		model.session.commit()
		model.session.refresh(trip)

	return redirect(url_for("view_packinglist", id=trip.id))

@app.route("/trip/<int:id>")
@login_required
def view_trip(id):
	trip = Trip.query.get(id)
	packing_list = PackingList.query.filter_by(trip_id=trip.id).first()
	pack_items_list = PackListItems.query.filter_by(packing_list_id=packing_list.id).all()
	activity_list = TripActivity.query.filter_by(trip_id=trip.id).all()

	return render_template("trip.html", trip=trip, packing_list=packing_list, pack_items_list=pack_items_list, activity_list=activity_list)


@app.route("/trip/<int:id>")
@login_required
def view_packinglist(id):
	trip = Trip.query.get(id)
	return render_template("trip.html", trip = trip)








@app.route("/settings")
@login_required
def settings():
	return render_template("settings.html")





@app.route("/logout")
@login_required
def logout():
    session.clear()
    return redirect(url_for("index"))

if __name__ == "__main__":
    app.run(debug=True)
开发者ID:spohlson,项目名称:Travel_Social,代码行数:97,代码来源:views.py

示例13: authenticate

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import set_password [as 别名]
def authenticate():
    if request.form['btn'] == "login": 
        form_login = forms.LoginForm(request.form)

        if not form_login.validate():
            flash("Incorrect username or password") 
            return render_template("login.html")

        email = form_login.email.data
        password = form_login.password.data

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

        if not user or not user.authenticate(password):
            flash("Incorrect username or password")         
            return render_template("login.html")

        login_user(user)
        session["user_id"] = user.id
        return redirect(request.args.get("next", url_for("browse")))

    elif request.form['btn'] == "register":
        register_Form = forms.RegisterForm(request.form)
        if not register_Form.validate():
            flash("Invalid email")
            return render_template("login.html")
        email = request.form.get("email")
        if User.query.filter_by(email=email).all():
            flash("User email already exists")         
            return render_template("login.html")
        first_name=request.form.get("first_name")
        last_name=request.form.get("last_name")
        creator = bool(request.form.get("role"))
        if not first_name or not last_name:
            flash("Please enter information in all fields")
            return render_template("login.html")
        password = request.form.get("password")
        verify_password = request.form.get("verify")
        if password != verify_password:
            flash("Passwords do not match")
            return render_template("login.html")
        new_user = User(email=email, first_name=first_name, last_name=last_name, campaignCreator=creator)
        new_user.set_password(password=password)
        model.session.add(new_user)
        model.session.commit()

        session['user_id'] = new_user.id
        if creator:
            return redirect(url_for("create_info"))
        return redirect(url_for("create_supporter"))

    elif request.form['btn'] == "fb_login":
        print "AJAX request data:"
        fb_id = request.form.get('fb_id')
        user = User.query.filter_by(fb_id=fb_id).first()
        # If user's fb id exists in database, log in user 
        if user: 
            login_user(user)
            session["user_id"] = user.id

        elif current_user.is_anonymous():
            # create an account based on their FB data
            print "creating a new user for %s" % request.form.get('first_name')
            #img_url = "https://graph.facebook.com/%s/picture?type=small" % fb_id 
            #print img_url
            user = User(
                email=request.form.get('email'),
                first_name=request.form.get('first_name'),
                last_name=request.form.get('last_name'),
                fb_id=fb_id,
            )
            user.set_password('python')
            model.session.add(user)
            model.session.commit()
            session['user_id'] = new_user.id

        elif not current_user.fb_id:
            # make sure we already have their FB ID stored with their account
            current_user.fb_id = fb_id
            model.session.commit()

        return ""
开发者ID:nsamsami,项目名称:csgo,代码行数:84,代码来源:controller.py


注:本文中的model.User.set_password方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。