示例#1
0
def login():
	if request.method == 'POST':
	    data = request.json
		# data = request.Form
		username = data.get('username', None)
		print(username)
		password = data.get('password', None)
		org = data.get('organization', None)
		# first verify user in database
		if username in {u.name: u for u in UserBusiness.find_all_users()}:
			# then verify the user password
			if UserBusiness.verify_password(org, username, password):
				#  user = UserBusiness.find_user_by_name(username)
				ret = {'access_token': create_access_token(identity=username),
					   'refresh_token': create_refresh_token(identity=username)
					   }
				# Return the double submit values in the resulting JSON
				# instead of in additional cookies
				# resp = jsonify({
				#     'access_csrf' : get_csrf_token(ret['access_token']),
				#     'refresh_csrf': get_csrf_token(ret['refresh_token'])
				# })
				
				# Set the JWT cookies in the response
				resp = jsonify({'login': True})
				
				print(ret['access_token'])
				set_access_cookies(resp, ret['access_token'])
				set_refresh_cookies(resp, ret['refresh_token'])
				print("done")
				return resp, 200
			return jsonify({"msg": "Bad password"}), 403
		return jsonify({"msg": "Username is not exists!"}), 404
示例#2
0
def login():
    username = request.json.get('username', None)
    print(username)
    password = request.json.get('password', None)
    org = request.json.get('organization', None)
    # first verify user in database

    if username not in {u.name: u for u in UserBusiness.find_all_users()}:
        return jsonify({"msg": "Username is not exists!"}), 401
    # then verify the user password

    if UserBusiness.verify_password(org, username, password) is False:
        return jsonify({"msg": "Bad password"}), 401
        #  user = UserBusiness.find_user_by_name(username)
    if username != 'mysql' or password != '123456':
        return jsonify({'login': False}), 401
    ret = {
        'access_token': create_access_token(identity=username),
        'refresh_token': create_refresh_token(identity=username)
    }
    # Create the tokens we will be sending back to the user
    access_token = create_access_token(identity=username)
    refresh_token = create_refresh_token(identity=username)

    # Set the JWT cookies in the response
    resp = jsonify({'login': True})

    print(ret['access_token'])
    set_access_cookies(resp, access_token, 123456789)
    set_refresh_cookies(resp, refresh_token)
    print("done")
    return jsonify(ret), 200
示例#3
0
def login():
    username = request.json.get('username', None)
    print(username)
    password = request.json.get('password', None)
    org = request.json.get('organization', None)
    # first verify user in database

    if username in {u.name: u for u in UserBusiness.find_all_users()}:
        return jsonify({"msg": "Username is not exists!"}), 401

    # then verify the user password
    if UserBusiness.verify_password(org, username, password):
        #  user = UserBusiness.find_user_by_name(username)
        ret = {
            'access_token': create_access_token(identity=username),
            'refresh_token': create_refresh_token(identity=username)
        }

        # Set the JWT cookies in the response
        resp = jsonify({'login': True})

        print(ret['access_token'])
        set_access_cookies(resp, ret['access_token'])
        set_refresh_cookies(resp, ret['refresh_token'])
        print("done")

        return jsonify(ret), 200
    return jsonify({"msg": "Bad password"}), 401
示例#4
0
# -*- coding: UTF-8 -*-

from business.user_business import UserBusiness
from database.config_setting import app, date_time
from services.permission_service import PermissionService
from services.role_service import RoleService
from services.user_group_service import UserGroupService

if __name__ == '__main__':

    users = UserBusiness.find_all_users()
    for i in users:
        print(i)
        # UserBusiness.reset_password(i.name)

    print(date_time.strftime('%Y-%m-%d %H:%M:%S'))

    # PermissionService.add_permission_by_name('baidu')
    # PermissionService.delete_permission_by_name('除去用户')
    roles = PermissionService.find_roles_by_perm('添加用户')
    for i in roles:
        print(i)

    perms = PermissionService.find_perm_by_role('管理员Admin')
    for j in perms:
        print(j)

    PermissionService.add_permission_by_role_name('添加坐标', '管理员Admin')
    PermissionService.remove_permission_by_name('添加坐标', '管理员Admin')
    perms = PermissionService.find_perm_by_resource('新风设备1')
    for i in perms:
示例#5
0
def users_manage():
    users = UserBusiness.find_all_users()
示例#6
0
 def identity(cls, payload):
     user_id = payload['identity']
     return {u.id: u for u in UserBusiness.find_all_users()}.get(user_id,
                                                                 None)
示例#7
0
 def authenticate(cls, username, password):
     user = {u.name: u for u in UserBusiness.find_all_users()}.get(username,
                                                                   None)
     if user and safe_str_cmp(user.password.encode('utf-8'),
                              password.encode('utf-8')):
         return user
示例#8
0
print("用户-多角色显示:")
for role in roles:
    if role is not None:
        print(role)
# x = User.query.with_parent(r_user_role)
# print x

group = Usergroup(name=u'弱鸡', create_by='Super User')
db.session.add(group)
print(group)
# nenber.group.append(group)

xxx = UserBusiness()
print(xxx)
# 查询所有用户列表
users = xxx.find_all_users()
if users is not None:
    for user in users:
        print(user)

# 通过用户id 来进行删除 (√)
# user = xxx.delete_user_by_id(18)
# print user

# 密码的更新,总提示参数不对。
# xxx.update_pwd(name='Brand',pwd=m.update('123'))

# 输出根据id 去查询用户信息
print('start\n')
user5 = xxx.find_user_by_id(1)
print('user - id ==5:', user5)