コード例 #1
0
    def auth_external(self, form):

        if (env.getenv('EXTERNAL_LOGIN') != 'True'):
            failed_result = {
                'success': 'false',
                'reason': 'external auth disabled'
            }
            return failed_result

        result = external_receive.external_auth_receive_request(form)

        if (result['success'] != 'True'):
            failed_result = {'success': 'false', 'result': result}
            return failed_result

        username = result['username']
        user = User.query.filter_by(username=username).first()
        if (user != None and user.auth_method == result['auth_method']):
            result = {
                "success": 'true',
                "data": {
                    "username": user.username,
                    "avatar": user.avatar,
                    "nickname": user.nickname,
                    "description": user.description,
                    "status": user.status,
                    "group": user.user_group,
                    "token": user.generate_auth_token(),
                }
            }
            return result
        if (user != None and user.auth_method != result['auth_method']):
            result = {
                'success': 'false',
                'reason': 'other kinds of account already exists'
            }
            return result
        #user == None , register an account for external user
        newuser = self.newuser()
        newuser.username = result['username']
        newuser.password = result['password']
        newuser.avatar = result['avatar']
        newuser.nickname = result['nickname']
        newuser.description = result['description']
        newuser.e_mail = result['e_mail']
        newuser.truename = result['truename']
        newuser.student_number = result['student_number']
        newuser.status = result['status']
        newuser.user_group = result['user_group']
        newuser.auth_method = result['auth_method']
        newuser.department = result['department']
        newuser.tel = result['tel']
        self.register(user=newuser)
        user = User.query.filter_by(username=username).first()
        result = {
            "success": 'true',
            "data": {
                "username": user.username,
                "avatar": user.avatar,
                "nickname": user.nickname,
                "description": user.description,
                "status": user.status,
                "group": user.user_group,
                "token": user.generate_auth_token(),
            }
        }
        return result
コード例 #2
0
ファイル: userManager.py プロジェクト: DreamReaver/docklet
    def auth_external(self, form):

        if (env.getenv('EXTERNAL_LOGIN') != 'True'):
            failed_result = {'success': 'false', 'reason' : 'external auth disabled'}
            return failed_result

        result = external_receive.external_auth_receive_request(form)

        if (result['success'] != 'True'):
            failed_result =  {'success':'false',  'result': result}
            return failed_result

        username = result['username']
        user = User.query.filter_by(username = username).first()
        if (user != None and user.auth_method == result['auth_method']):
            result = {
                "success": 'true',
                "data":{
                    "username" : user.username,
                    "avatar" : user.avatar,
                    "nickname" : user.nickname,
                    "description" : user.description,
                    "status" : user.status,
                    "group" : user.user_group,
                    "token" : user.generate_auth_token(),
                }
            }
            return result
        if (user != None and user.auth_method != result['auth_method']):
            result = {'success': 'false', 'reason': 'other kinds of account already exists'}
            return result
        #user == None , register an account for external user
        newuser = self.newuser();
        newuser.username = result['username']
        newuser.password = result['password']
        newuser.avatar = result['avatar']
        newuser.nickname = result['nickname']
        newuser.description = result['description']
        newuser.e_mail = result['e_mail']
        newuser.truename = result['truename']
        newuser.student_number = result['student_number']
        newuser.status = result['status']
        newuser.user_group = result['user_group']
        newuser.auth_method = result['auth_method']
        newuser.department = result['department']
        newuser.tel = result['tel']
        self.register(user = newuser)
        user = User.query.filter_by(username = username).first()
        result = {
            "success": 'true',
            "data":{
                "username" : user.username,
                "avatar" : user.avatar,
                "nickname" : user.nickname,
                "description" : user.description,
                "status" : user.status,
                "group" : user.user_group,
                "token" : user.generate_auth_token(),
            }
        }
        return result