Esempio n. 1
0
 def create_user(self, username, password):
     try:
         user = UserDB(name=username, password=password)
         user.commit(True)
         return user.to_json()
     except:
         return False
Esempio n. 2
0
 def check_login(self, data):
     print(data)
     user = UserDB.objects(name=data['username'],
                           password=data['password']).first()
     if user is None:
         return False
     else:
         return user.to_json()
Esempio n. 3
0
	def post(self):
		try:
			username, password = self.get_argument("username"), self.get_argument("password")
			print("%-20s username %s try to login." % (self.trans_id,username))          
			token = User().set_user_token(username,password)
			if not token:
			    print("%-20s username %s failed to login." % (self.trans_id,username))
			    self.render("Login.html", msg='badLoginCerd')
			    return
			self.set_secure_cookie('auth', token, expires_days=1)
			redirect_path = self.request.arguments.get('next',['/index'])
			self.redirect(redirect_path[0])
		except:
			self.render("Login.html", msg='Something wrong')
Esempio n. 4
0
 def set_user_token(self, username, password):
     user = UserDB.objects(name=username).first()
     if user is None:
         return False
     if not user.Status:
         return False
     if user.check_user_pass(password):
         payload = {'username': user['name'], '_id': user['_id']}
         return jwt.encode(
             payload,
             'rWxHp4CBC8h0SiPY3gPKIGbed14bBCsj0VK8RQrrmKqa0ZveQvXNd7MI2twENvVJHq7vdYJHWPhLq5ONA8nr6bbZenANIrynBUEVbMHpMud3K8iUSAanfKTZ',
             algorithm='HS256')
     else:
         return False
Esempio n. 5
0
 def create_user(self, username, password):
     try:
         user = UserDB(name=username)
         user.change_password(plain_password)
         extra['username'] = self.username
         extra['remote_ip'] = self.remote_ip
         user.commit(True)
         return user.to_json()
     except:
         return dict(error='The user %s already exiest.' % username)
Esempio n. 6
0
 def user_by_name(self, name):
     return UserDB.objects(name=name)
Esempio n. 7
0
 def users(self):
     return UserDB.objects()
Esempio n. 8
0
 def delete_user(self, id):
     user = UserDB(pk=id)
     user.delete()
     return UserDB.objects()