本文整理汇总了Python中models.User.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
print 'Hello World'
myDB = MysqlPython('thinkman-wang.com', 'thinkman', 'Ab123456', 'db_thinknews')
szSql = 'select * from user'
result = myDB.select_advanced(szSql)
for obj in result :
user = User()
user.id, user.user_name, user.password = obj
print("%d | %s | %s" % (user.id, user.user_name, user.password))
lstUser = get_all_users()
for user in lstUser :
print("%d | %s | %s" % (user.id, user.user_name, user.password))
lstUser = get_all_user_from_pool();
for user in lstUser :
print("%d | %s | %s" % (user.id, user.user_name, user.password))
print obj2json(lstUser)
user = login("18621675203", "a0a475cf454cf9a06979034098167b9e")
if (user != None):
print obj2json(user)
else:
print("login failed")
szToken = ("%s%d" % ("a0a475cf454cf9a06979034098167b9e", int(time.time())))
print(hashlib.md5(szToken).hexdigest())
示例2: create_user
def create_user(self):
u = User(_DBCON)
u.email = self.EMAIL
u.password = self.PASSWORD
u.save()
return u
示例3: change_password_post
def change_password_post():
random_token = request.form.get('change-password-random-token', '')
p_c_r = Password_Change_Requests.select_by_id(random_token, 1)
if request.is_xhr and len(p_c_r) is not 0 and Password_Change_Requests.is_valid_random_token(p_c_r[0]['datetime']):
p_c_r = p_c_r[0]
new_password = request.form.get('change-password-new-password', '')
confirm_new_password = request.form.get('change-password-confirm-new-password', '')
language = session.get('language', 'en')
error_list = list()
if not User.is_password_valid(new_password):
error_list.append(strings.STRINGS[language]['INVALID_PASSWORD'])
if new_password != confirm_new_password:
error_list.append(strings.STRINGS[language]['PASSWORD_NO_MATCH'])
if len(error_list) is not 0:
return make_response(jsonify(error_list = error_list), 400)
else:
User.update_password(p_c_r['user_id'], new_password)
Password_Change_Requests.delete(p_c_r['user_id'])
session['user_logged_id'] = p_c_r['user_id']
username = User.select_by_id(p_c_r['user_id'], 1)[0]['username']
return jsonify(url = '/profile/' + username)
else:
return redirect('/404')
示例4: index
def index():
e = bottle.request.POST.get('email')
p1 = bottle.request.POST.get('password1')
p2 = bottle.request.POST.get('password2')
if e and p1 and p2:
if p1 != p2:
return bottle.template('register', error='The passwords do not match', email=e, password1=p1, password2=p2)
else:
u = User(_DBCON, email=e, password=p1)
if u._id:
return bottle.template('register', error='An account already exists for that email address', email=e, password1=p1, password2=p2)
else:
u.save()
e = Email(recipient=e)
e.send('Places accounts activation', '<a href="%s/activate/%s">Activate</a>' % (settings.BASEURL, u.token))
return bottle.redirect('/success')
else:
vd = {
#'date':datetime.datetime.now().strftime('%Y'),
'baseurl':settings.BASEURL,
}
return bottle.template('register', error='Please complete the form', email=e or '', password1=p1 or '', password2=p2 or '', vd=vd)
示例5: post
def post(self, *args, **kwargs):
user_uuid = self.get_argument('uuid', '')
user = User.by_uuid(user_uuid)
if user is not None:
errors = []
username = self.get_argument('username', None)
password = self.get_argument('password', None)
if password is not None:
if 12 <= len(password) <= 100:
self.change_user_password(user)
else:
errors.append("Password invalid length (12-100)")
if username is not None and username != user.username:
if 3 <= len(username) <= 15:
if User.by_username(username) is None:
user.username = username
dbsession.add(user)
dbsession.flush()
else:
errors.append("Username already exists")
else:
errors.append("Username is an invalid length (3-15)")
self.render("admin/manage_users.html", errors=errors)
else:
self.render("admin/manage_users.html",
errors=["User does not exist"]
)
示例6: get
def get(self, *args, **kwargs):
self.errors = []
# перезагружаем конфигурацию приложения
self.application.loadConfiguration()
self.removeDBSessions()
# миграция БД
password = None
try:
connection = self.getDBSession()
migrate(connection = connection)
except BaseException as exception:
self.errors.append(u'Ошибка при миграции БД: ' + exception.message)
else:
# create admin user
password = hashlib.sha256(str(time.time())).hexdigest()[5:11]
user = User()
user.fullname = 'Admin'
user.login = 'admin'
user.password = hashlib.sha256(password).hexdigest()
user.role = User.ROLE_ADMIN
try:
connection.merge(user)
connection.commit()
except BaseException as exception:
self.errors.append(u'Ошибка при создани пользователя: ' + exception.message)
else:
self.application.isInstalled = True
self.render('install/end.jinja2', {'errors': self.errors, 'admin_pass': password})
示例7: contribution_requests_refuse
def contribution_requests_refuse():
contribution_request_id = request.form.get('contribution_request_id', -1)
contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)
if len(contribution_request) is not 0:
contribution_request = contribution_request[0]
tale = Tale.select_by_id(contribution_request['tale_id'], 1)[0]
if tale['creator_id'] is session.get('user_logged_id', None):
Contribution_Request.update_was_accepted(contribution_request['id'], False)
Tale.update_contribution_request_count(contribution_request['tale_id'], -1)
creator = User.select_by_id(tale['creator_id'], 1)[0]
contributor = User.select_by_id(contribution_request['user_id'], 1)[0]
email_object = strings.construct_contribution_request_refused_email_object(
session.get('language', 'en'),
tale,
creator,
contributor,
contribution_request['id']
)
aux.send_email_to_followers(tale['id'], email_object['title'], email_object['body'])
return redirect('/tale/' + str(contribution_request['tale_id']) + '/0')
else:
return redirect('/404')
else:
return redirect('/404')
示例8: invite_post
def invite_post(tale_id):
username = request.form.get('invite-username', '')
user = User.select_by_email(username, 1)
tale = Tale.select_by_id(tale_id, 1)
if len(user) is 0:
user = User.select_by_full_username(username, 1)
if len(user) is not 0 and len(tale) is not 0 and session.get('user_logged_id', None) is tale[0]['creator_id']:
user = user[0]
tale = tale[0]
new_invitation = Invitation(session['user_logged_id'], user['id'], tale_id)
new_invitation.insert()
creator = User.select_by_id(tale['creator_id'], 1)[0]
email_object = strings.construct_tale_invitation_email_object(
session.get('language', 'en'),
user,
tale,
creator
)
aux.send_email(email_object['title'], user['email'], email_object['body'])
return redirect('/tale/' + str(tale_id) + '/0')
示例9: testValidEmail
def testValidEmail(self):
e, err = User.valid_email(email1)
self.assertEqual(e, True, "With no existing user")
u = User.save(username1, email1, password1)
# u.put()
e, err = User.valid_email(email1)
self.assertEqual(e, False, "After create user with the email being tested")
示例10: init_QA
def init_QA():
is_student_exist = False
is_lecturer_exist = False
qa_student = User(username='qa_student', name='Student QA', avatar_url='http://ava.com', email='[email protected]',
isLecturer=False, accessToken='student_token_', seToken='_QA_TOKEN_TEST_STUDENT')
qa_lecturer = User(username='qa_lecturer', name='Student QA', avatar_url='http://ava.com', email='[email protected]',
isLecturer=True, accessToken='student_token_', seToken='_QA_TOKEN_TEST_LECTURER')
query = User.all().filter('username =', qa_student.username)
for u in query.run():
is_student_exist = True
u.isLecturer = qa_student.isLecturer
u.seToken = qa_student.seToken
u.campuses_id_list = []
u.classes_id_list = []
db.put(u)
query = User.all().filter('username =', qa_lecturer.username)
for u in query.run():
is_lecturer_exist = True
u.isLecturer = qa_lecturer.isLecturer
u.seToken = qa_lecturer.seToken
u.campuses_id_list = []
u.classes_id_list = []
db.put(u)
if not is_lecturer_exist:
db.put(qa_lecturer)
if not is_student_exist:
db.put(qa_student)
return Response(status=200)
示例11: setUp
def setUp(self):
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
self.u1 = User.save(username1, email1, password1)
self.u2 = User.save(username2, email2, password2)
示例12: post
def post(self, *args, **kwargs):
''' Attempts to create an account, with shitty form validation '''
# Check user_name parameter
try:
user_name = self.get_argument('username')
except:
self.render('public/registration.html', errors = 'Please enter a valid account name')
# Check handle parameter
try:
handle = self.get_argument('handle')
except:
self.render('public/registration.html', errors = 'Please enter a valid handle')
# Check password parameter
try:
password1 = self.get_argument('pass1')
password2 = self.get_argument('pass2')
if password1 != password2:
self.render('public/registration.html', errors = 'Passwords did not match')
else:
password = password1
except:
self.render('public/registration.html', errors = 'Please enter a password')
# Check recaptcha
try:
response = captcha.submit(
self.get_argument('recaptcha_challenge_field'),
self.get_argument('recaptcha_response_field'),
self.application.settings['recaptcha_private_key'],
self.request.remote_ip,)
except:
self.render('public/registration.html', errors = "Please fill out recaptcha!")
# Create account
if User.by_user_name(user_name) != None:
self.render('public/registration.html', errors = 'Account name already taken')
elif user_name == handle:
self.render('public/registration.html', errors = 'Account name and hacker name must differ')
elif User.by_display_name(handle) != None:
self.render('public/registration.html', errors = 'Handle already taken')
elif not 0 < len(password) <= 7:
self.render('public/registration.html', errors = 'Password must be 1-7 characters')
elif not response.is_valid:
self.render('public/registration.html', errors = 'Invalid Recaptcha!')
else:
char_white_list = ascii_letters + digits
user_name = filter(lambda char: char in char_white_list, user_name)
display_name = filter(lambda char: char in char_white_list, handle)
user = User(
user_name = unicode(user_name),
display_name = unicode(display_name),
password = password
)
self.dbsession.add(user)
self.dbsession.flush()
self.redirect('/login')
示例13: new_users
def new_users():
users = json.loads(request.data)
users = users['users']
session = Session()
for user in users:
User.get_or_create_temp(session, user)
return jsonify({'received': 'true'})
示例14: activate_token
def activate_token(self, token):
u = User(_DBCON)
if u.activate(token):
self._login_user(u)
else:
self.viewdata.update({"error": "The token does not match any account that is pending activation"})
return self._template("error")
示例15: test_activate_user_good_token
def test_activate_user_good_token(self):
self.create_user()
user = _DBCON.User.find_one()
u = User(_DBCON)
self.assertTrue(u.activate(user['token']))
self.assertTrue(u.valid)
self.assertTrue(u.email == self.EMAIL)