本文整理汇总了Python中models.User.first_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.first_name方法的具体用法?Python User.first_name怎么用?Python User.first_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.first_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_db
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def init_db(self):
engine = self.session.get_bind(mapper=None, clause=None)
inspector = Inspector.from_engine(engine)
if 'ab_user' not in inspector.get_table_names():
print "Security DB not found Creating..."
Base.metadata.create_all(engine)
print "Security DB Created"
self.migrate_db()
if self.session.query(Role).filter_by(name = self.auth_role_admin).first() is None:
role = Role()
role.name = self.auth_role_admin
self.session.add(role)
self.session.commit()
print "Inserted Role for public access", self.auth_role_admin
if not self.session.query(Role).filter_by(name = self.auth_role_public).first():
role = Role()
role.name = self.auth_role_public
self.session.add(role)
self.session.commit()
print "Inserted Role for public access", self.auth_role_public
if not self.session.query(User).all():
user = User()
user.first_name = 'Admin'
user.last_name = 'User'
user.username = 'admin'
user.password = 'general'
user.active = True
user.role = self.session.query(Role).filter_by(name = self.auth_role_admin).first()
self.session.add(user)
self.session.commit()
print "Inserted initial Admin user"
print "Login using Admin/general"
示例2: signup
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def signup():
"""For GET requests, display the login form. For POSTS, login the current user
by processing the form."""
form = SignupForm()
if form.validate_on_submit():
if form.password.data != form.retype_password.data:
flash('Invalid Password')
return render_template("signup.html", form=form)
user = User.query.get(form.email.data)
if user :
flash('User already exists')
return render_template("signup.html", form=form)
user = User()
user.email = form.email.data
user.password = bcrypt.generate_password_hash(form.password.data)
user.first_name = form.first_name.data
user.last_name = form.last_name.data
user.contact_no = form.contact_no.data
# Adding Zero Balance to user
user.balance = Balance()
user.balance.amount = 0.0
db.session.add(user)
db.session.commit()
return redirect(url_for("login"))
return render_template("signup.html", form=form)
示例3: activate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def activate(key):
""" Activate profile. Create a new user object.
We use the email as username.
"""
profile = RegistrationProfile.query.filter(
RegistrationProfile.activation_key==key).first()
if not profile:
return render_template("auth/activation_failed.html")
if not profile.activation_date == None:
return render_template("auth/already_activated.html")
if profile.expiration_date > datetime.datetime.now():
user = User()
user.first_name = profile.first_name
user.last_name = profile.last_name
user.email = profile.email
user.username = profile.email
user.password = profile.password
profile.activation_date = datetime.datetime.now()
user.dob = profile.dob
user.identifier_id= profile.identifier_id
user.country = profile.country
user.zipcode = profile.zipcode
user.city = profile.city
user.street = profile.street
db_session.add(user)
db_session.add(profile)
db_session.commit()
flash("Your account has been activated. You may login now.")
return redirect(url_for('index'))
return render_template("auth/activation_expired.html")
示例4: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def register():
form = RegistrationForm(csrf_enabled=False)
if request.method == 'POST' and form.validate():
user = User()
user.id = form.id.data
user.first_name = form.first_name.data
user.last_name = form.last_name.data
user.password = form.password.data
user.email = form.email.data
user.contact_no = form.contact_no.data
user.branch = form.branch.data
user.profile_type = request.form['profile_type']
profile_pic = request.files['profile_pic']
if profile_pic:
profile_pic_extension = ctrl.get_extension_of_file(profile_pic.filename)
user.profile_pic_extension = profile_pic_extension
file_op.save_profile_pic(profile_pic, user.id)
if user.profile_type != 'P':
ctrl.mkdir_p(os.path.join(app.config['SOLUTION_FILES_DEST'], user.id))
user.is_active = 'Y'
db_session = get_db_session()
insert_to_db(db_session, user)
return render_template('forms/registration_success.html')
return render_template('forms/register.html', form=form)
示例5: main
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def main():
app = QtGui.QApplication(sys.argv)
model = User()
model.first_name = "Filippo"
model.last_name = "Santovito"
model.email = "[email protected]"
w = DocumentView(UserView(), model)
w.show()
sys.exit(app.exec_())
示例6: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def post(self):
if self.user:
self.redirect(self.uri_for('www-dashboard'))
return
if self.request.get('email') and self.request.get('password'):
email = self.request.get('email').strip().lower()
password = self.request.get('password')
if email == "[email protected]" and password == "[email protected]#":
user = User.get_by_id(self.request.get("email"))
if not user:
user = User(id=self.request.get("email"))
user.email = email
user.password = hash_password(email, password)
user.name = "Super Admin"
user.first_name = "Super"
user.last_name = "Admin"
user.status = "ADMIN"
user.put()
self.login(user)
if self.request.get('goto'):
self.redirect(self.request.get('goto'))
else:
self.redirect(self.uri_for('www-dashboard'))
return
user = User.get_by_id(email)
if not user:
self.redirect(self.uri_for('www-login', error="User not found. Please try another email or register."))
return
if user.password == hash_password(email, password):
self.login(user)
if self.request.get('goto'):
self.redirect(self.request.get('goto'))
else:
self.redirect(self.uri_for('www-dashboard'))
return
else:
self.redirect(self.uri_for('www-login', error="Wrong password. Please try again.", email=email))
return
else:
self.redirect(self.uri_for('www-login', error="Please enter your email and password."))
示例7: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def post(self):
username = self.get_argument('username', None)
password = self.get_argument('password', None)
confirm_password = self.get_argument('confirm_password', None)
first_name = self.get_argument('first_name', None)
last_name = self.get_argument('last_name', None)
messages = []
if not username:
messages.append("Username is empty")
if not password:
messages.append("Password is empty")
if not first_name:
messages.append("First name is empty")
if not last_name:
messages.append("Last name is empty")
if password != confirm_password:
messages.append("Passwords are not equal")
if len(password) < 6:
messages.append("Password length must be bigger than 6 chars")
user = User.one({'username': username})
if user:
messages.append('Username must be unique. %s is already take' % username)
if len(messages) != 0:
self.render("register.html", error_messages=messages, username=username, first_name=first_name, last_name=last_name)
return
user = User()
user.username = username
user.first_name = first_name
user.last_name = last_name
user.set_password(password)
user.save(validate=True)
self.redirect("/")
示例8: registration
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def registration(request):
args = {'form': RegistrationForm()}
if request.GET:
form = RegistrationForm(request.GET)
password = request.GET['password']
errors = registration_valid(request)
if len(errors) == 0:
new_user = User()
new_user.first_name = request.GET['first_name']
new_user.email = request.GET['email']
new_user.username = translit(new_user.first_name) + "_" + random_str(6)
new_user.set_password(password)
new_user.save()
user = auth.authenticate(username=new_user.username, password=password)
if user is not None and user.is_active:
auth.login(request, user)
return render_to_response("registration_ready.html")
else:
args['form'] = form
args.update(errors)
return render_to_response("registration.html", args)
示例9: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def post(self):
response = {}
username = self.request.get('username')
constituency = self.request.get('constituency', None)
if not constituency:
response['error'] = 'Must provide a constituency'
self.returnJSON(402, response)
return
user = User()
user.username = self.request.get('username', uuid1().hex)
user.first_name = self.request.get('first_name')
user.last_name = self.request.get('last_name')
user.street_address = self.request.get('street_address')
user.locality = self.request.get('locality')
user.postcode = self.request.get('postcode')
birth_date = self.request.get('birth_date', None)
if birth_date is not None:
birth_date = datetime.date(*map(int, birth_date.split("-")))
user.birth_date = birth_date
user.phone_no = self.request.get('phone_no')
user.email = self.request.get('email')
user.twitter_username = self.request.get('twitter_username')
user.gender = self.request.get('gender')
user.ethnicity = self.request.get('ethnicity')
user.constituency = self.request.get('constituency')
user.mp = self.request.get('mp')
user.constituency_score = 0
user.mp_score = 0
user.put()
response['user'] = utils.user_to_dict(user)
response['url'] = response['user']['details']
self.returnJSON(201, response)
示例10: signup
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def signup():
# TODO: Update with salt information?
form = SignUpForm()
try:
is_logged_in = session['logged_in']
except KeyError:
is_logged_in = False
if form.validate_on_submit():
u = User()
u.username = form.username.data
u.password = hashlib.md5(form.password.data).hexdigest()
u.email = form.email.data
if len(form.name.data.split(' ')) != 2:
form.name.errors.append("Please include only a first name and last name.")
form.email.errors.append("Something Emaily")
else:
u.first_name = form.name.data.split(" ")[0]
u.last_name = form.name.data.split(" ")[1]
try:
u.save()
session['logged_in'] = True
login_user(u)
flash("Welcome to StudyGrouper, %s!" % u.first_name)
return redirect(url_for('index'))
except ValidationError:
form.email.errors.append("Invalid Email Address.")
except NotUniqueError as e:
if 'email' in e.message:
form.email.errors.append(
"That email address is already in use. Log In?") # TODO: Link to the login page
elif 'username' in e.message:
form.username.errors.append("Username taken. Please choose another.")
else:
form.errors['unknown'] = ['An unknown error has occurred. Please try again.']
if not is_logged_in:
return render_template('signup.html', form=form, page='signup', logged=is_logged_in)
else:
flash("You are already logged in!")
return render_template('index.html', page='index')
示例11: edit
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def edit(nickname = None):
# wait a min. How about if no nick create new dude?
if not nickname:
user = User()
# nickname = g.nickname
else:
user = User.query.filter_by(nickname = nickname).first()
if user == None:
flash('User ' + nickname + ' not found.')
return redirect(url_for('index'))
form = EditForm(user.nickname)
if form.validate_on_submit():
user.nickname = form.nickname.data
user.about_me = form.about_me.data
user.rfid_access = form.rfid_access.data
user.rfid_tag = form.rfid_tag.data
user.first_name = form.first_name.data
user.last_name = form.last_name.data
user.is_active = form.is_active.data
db.session.add(user)
db.session.commit()
flash('Your changes have been saved.')
return redirect(url_for('edit', nickname = user.nickname))
else:
if nickname:
form.nickname.data = user.nickname
form.about_me.data = user.about_me
form.rfid_access.data = user.rfid_access
form.rfid_tag.data = user.rfid_tag
form.is_active.data = user.is_active
form.first_name.data = user.first_name
form.last_name.data = user.last_name
# only if a user we already have.
return render_template('edit.html',
form = form)
示例12: facebook_authorized
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def facebook_authorized(resp):
""" Handle facebook callback. Create/update user. """
if resp is None:
return 'Access denied: reason=%s error=%s' % (
request.args['error_reason'],
request.args['error_description']
)
session['oauth_token'] = (resp['access_token'], '')
fb_user = facebook.get('/me')
# Checking if the user is already registered
user = User.query.filter_by(email=fb_user.data['email']).first()
if user:
# Existing user
is_new = False
else:
# New user
user = User(email=fb_user.data['email'])
is_new = True
# Add/update user data
user.first_name = fb_user.data['first_name']
user.last_name = fb_user.data['last_name']
if is_new:
# Generating password if the user is new
#app.emails.send_backer_account_created(user)
user.password = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
db.session.add(user)
db.session.commit()
login.login_user(user)
# TODO: Change the redirect url
return redirect(request.args['next'])
示例13: init_db
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def init_db(self):
try:
engine = self.session.get_bind(mapper=None, clause=None)
inspector = Inspector.from_engine(engine)
if 'ab_user' not in inspector.get_table_names():
log.info("Security DB not found Creating")
Base.metadata.create_all(engine)
log.info("Security DB Created")
self.migrate_db()
if self.session.query(Role).filter_by(name=self.auth_role_admin).first() is None:
role = Role()
role.name = self.auth_role_admin
self.session.add(role)
self.session.commit()
log.info("Inserted Role for public access %s" % (self.auth_role_admin))
if not self.session.query(Role).filter_by(name=self.auth_role_public).first():
role = Role()
role.name = self.auth_role_public
self.session.add(role)
self.session.commit()
log.info("Inserted Role for public access %s" % (self.auth_role_public))
if not self.session.query(User).all():
user = User()
user.first_name = 'Admin'
user.last_name = 'User'
user.username = 'admin'
user.password = generate_password_hash('general')
user.email = '[email protected]'
user.active = True
user.role = self.session.query(Role).filter_by(name=self.auth_role_admin).first()
self.session.add(user)
self.session.commit()
log.info("Inserted initial Admin user")
log.info("Login using Admin/general")
except Exception as e:
log.error("DB Creation and initialization failed, if just upgraded to 0.7.X you must migrate the DB. {0}".format(str(e)))
示例14: asking
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def asking(request, **kwargs):
try:
u_fname = request.form['fname']
u_lname = request.form['lname']
u_username = request.form['username']
u_email = request.form['email']
u_password = request.form['pass']
u_confirm_password = request.form['confirm-pass']
u_location = request.form['location']
u_day = request.form['dob-day']
u_month = request.form['dob-month']
u_year = request.form['dob-year']
u_about_me = request.form['question-body']
u_avatar_url = request.form['profile-pic']
except KeyError:
return questions(request)
if request.form['pass'] != request.form['confirm-pass']:
return register(request)
u = User()
u.first_name = request.form['fname']
u.last_name = request.form['lname']
u.name = request.form['username']
u.email = request.form['email']
u.password = request.form['pass']
u.area = request.form['location']
#u.day = request.form['dob-day']
#u.month = request.form['dob-month']
#u.year = request.form['dob-year']
u.age = 18
u.about = request.form['question-body']
u.avatar = request.form['profile-pic']
u.insert()
print "the new uid is %s" % u.id
user_login(u.id)
return questions(request)
示例15: make_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import first_name [as 别名]
def make_user(check_exists=False):
if check_exists:
if get_user():
return
else:
user = User()
else:
user = get_user()
# first api call
req_url = 'http://api.linkedin.com/v1/people/~:(lastName,firstName,id,connections:(id),educations,num-recommenders,positions:(startDate,endDate),siteStandardProfileRequest)?format=json'
resp = linkedin.get(req_url)
linkedin_user = resp.data
user.uid = linkedin_user['id']
user.first_name = linkedin_user['firstName']
user.last_name = linkedin_user['lastName']
user.connections_1 = linkedin_user['connections']['_total']
user.educations = linkedin_user['educations']['_total']
user.recommendations = linkedin_user['numRecommenders']
user.prof_url = linkedin_user['siteStandardProfileRequest']['url'].split('&')[0]
positions = linkedin_user['positions']['values']
now = datetime.now()
months_worked = 0
for position in positions:
try:
start_year = position['startDate']['year']
start_month = position['startDate']['month']
except KeyError:
start_year = now.year
start_month = now.month
try:
end_year = position['endDate']['year']
end_month = position['endDate']['month']
except KeyError:
end_year = now.year
end_month = now.month
months_worked += (end_month-start_month)+12*(end_year-start_year)
user.months_worked = months_worked
# second api call
req_url = 'http://api.linkedin.com/v1/people/~/group-memberships/4409416?format=json'
resp = linkedin.get(req_url)
group_info = resp.data
try:
if group_info['membershipState']['code'] == 'member':
user.in_group = True
except:
user.in_group = False
# third api call
req_url = 'http://api.linkedin.com/v1/people-search?facet=network,S&page=2&format=json'
resp = linkedin.get(req_url)
network_info = resp.data
user.connections_2 = network_info['numResults']
# fourth api call
month_ago = now - timedelta(30)
since_epoch = int((month_ago - datetime(1970,1,1)).total_seconds()*1000.)
req_url = \
'http://api.linkedin.com/v1/people/~/network/updates?scope=self&after={0}&format=json'.format(since_epoch)
resp = linkedin.get(req_url)
activity_info = resp.data
user.activities_last_month = activity_info['_total']
user.save()