当前位置: 首页>>代码示例>>Python>>正文


Python models.UserModel类代码示例

本文整理汇总了Python中corrdb.common.models.UserModel的典型用法代码示例。如果您正苦于以下问题:Python UserModel类的具体用法?Python UserModel怎么用?Python UserModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

 def login(self, email, password):
     """Account login handler.
         Returns:
             User account instance if successful otherwise None.
     """
     from corrdb.common.models import UserModel
     account = None
     if self.type == 'stormpath':
         try:
             _account = self.manager.application.authenticate_account(email, password).account
             if _account is not None:
                 account = UserModel.objects(email=email).first()
         except Error as re:
             print('Message: %s' %re.message)
             print('HTTP Status: %s' %str(re.status))
             print('Developer Message: %s' %re.developer_message)
             print('More Information: %s' %re.more_info)
             print('Error Code: %s' %str(re.code))
     elif self.type == 'api-token':
         # No login for api-token.
         pass
     elif self.type == 'mongodb':
         hash_pwd = hashlib.sha256(('CoRRPassword_%s'%password).encode("ascii")).hexdigest()
         account_1 = UserModel.objects(email=email).first()
         if account_1 != None:
             if account_1.password == None:
                 account_1.password = hash_pwd
                 account_1.save()
             account = account_1
         else:
             account = UserModel.objects(email=email, password=hash_pwd).first()
     if account and account.group == "unknown":
         account.group = "user"
         account.save()
     return account
开发者ID:faical-yannick-congo,项目名称:corr,代码行数:35,代码来源:access_manager.py

示例2: register

    def register(self, email, password, fname, lname, mname):
        """Registration handler.

        Returns:
          User account registered.
        """
        from corrdb.common.models import UserModel
        account = None
        _account = None
        check_password = self.password_check(password)
        if not check_password['password_ok']:
            message = ["Password rules vialation:"]
            if check_password['length_error']:
                message.append("Must be at least 8 characters.")
            if check_password['digit_error']:
                message.append("Must contain at least one digit.")
            if check_password['uppercase_error']:
                message.append("Must contain at least one upper case character.")
            if check_password['lowercase_error']:
                message.append("Must contain at least one lower case character.")
            if check_password['symbol_error']:
                message.append("Must contain at least one special character.")
            return False, message
        hash_pwd = hashlib.sha256(('CoRRPassword_%s'%password).encode("ascii")).hexdigest()
        if self.type == 'api-token':
            pass
        else:
            if self.type == 'mongodb':
                account = UserModel.objects(email=email).first()
            elif self.type == 'stormpath':
                try:
                    _account = self.manager.application.search(email).first()
                except:
                    _account = None
                if _account != None:
                    account = UserModel.objects(email=email).first()
            if account is None:
                if self.type == 'stormpath':
                    account = UserModel.objects(email=email).first()
                    if account is None:
                        (account, created) = get_or_create(document=UserModel, created_at=str(datetime.datetime.utcnow()), email=email, group='user', api_token=hashlib.sha256(('CoRRToken_%s_%s'%(email, str(datetime.datetime.utcnow()))).encode("ascii")).hexdigest())
                    if _account is None:
                        failure = self.create_account(email, password, fname, lname, mname)[0] is None
                        if failure:
                            account.password = hash_pwd
                            account.save()
                if self.type == 'mongodb':
                    account = UserModel.objects(email=email).first()
                    if account is None:
                        (account, created) = get_or_create(document=UserModel, created_at=str(datetime.datetime.utcnow()), email=email, group='user', api_token=hashlib.sha256(('CoRRToken_%s_%s'%(email, str(datetime.datetime.utcnow()))).encode("ascii")).hexdigest())
                    account.password = hash_pwd
                    account.save()
                account.save()
                return True, account
            else:
                return False, account

        return False, account
开发者ID:usnistgov,项目名称:corr,代码行数:58,代码来源:access_manager.py

示例3: login

    def login(self, email, password):
        """Account login handler.

        Returns:
          User account instance if successful otherwise None.
        """
        from corrdb.common.models import UserModel
        account = None
        if self.type == 'stormpath':
            try:
                _account = self.manager.application.authenticate_account(email, password).account
                if _account:
                    account = UserModel.objects(email=email).first()
                else:
                    _account = self.manager.application.search(email).first()
                    if _account is None:
                        failure = self.create_account(email, password, "FirstName", "LastName", "")[0] is None
                        if failure:
                            hash_pwd = hashlib.sha256(('CoRRPassword_%s'%password).encode("ascii")).hexdigest()
                            account = UserModel.objects(email=email, password=hash_pwd).first()
                        else:
                            account = UserModel.objects(email=email).first()
                    else:
                        account = None
            except Error as re:
                print('Message: %s' %re.message)
                print('HTTP Status: %s' %str(re.status))
                print('Developer Message: %s' %re.developer_message)
                print('More Information: %s' %re.more_info)
                print('Error Code: %s' %str(re.code))
        elif self.type == 'api-token':
            # No login for api-token.
            pass
        elif self.type == 'mongodb':
            hash_pwd = hashlib.sha256(('CoRRPassword_%s'%password).encode("ascii")).hexdigest()
            account_1 = UserModel.objects(email=email).first()
            if account_1:
                if account_1.password is None:
                    account_1.password = hash_pwd
                    account_1.save()
                    account = account_1
                else:
                    account = UserModel.objects(email=email, password=hash_pwd).first()
            else:
                # (account, created) = get_or_create(document=UserModel, created_at=str(datetime.datetime.utcnow()), email=email, group='user', api_token=hashlib.sha256(('CoRRToken_%s_%s'%(email, str(datetime.datetime.utcnow()))).encode("ascii")).hexdigest())
                # account.password = hash_pwd
                # account.save()
                account = None
        if account and account.group == "unknown":
            account.group = "user"
            account.save()
        if account:
            account.connected_at = str(datetime.datetime.utcnow())
            if account.auth in ["wrong1", "wrong2", "wrong3"]:
                account.auth = "approved"
            account.save()
        return account
开发者ID:usnistgov,项目名称:corr,代码行数:57,代码来源:access_manager.py

示例4: check_api

 def check_api(self, token, acc_sec=False, cnt_sec=False):
     from corrdb.common.models import UserModel
     """Get the user object instance from its api token.
         Returns:
             The user object instance.
     """
     print([user.extended() for user in UserModel.objects()])
     account = UserModel.objects(api_token=token).first()
     if account.extend.get('access', 'verified') != 'verified':
         return None
     else:
         return account
开发者ID:faical-yannick-congo,项目名称:corr,代码行数:12,代码来源:access_manager.py

示例5: record_comment

def record_comment(hash_session, record_id):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/record/comment/<record_id>")
    if not created:
        traffic.interactions += 1 
        traffic.save()
        
    if fk.request.method == 'POST':
        current_user = UserModel.objects(session=hash_session).first()
        print fk.request.path
        if current_user is not None:
            try:
                record = RecordModel.objects.with_id(record_id)
            except:
                print str(traceback.print_exc())
            if record is None:
                return fk.redirect('http://0.0.0.0:5000/error-204/')
            else:
                if record.project.owner == current_user:
                    if fk.request.data:
                        data = json.loads(fk.request.data)
                        comment = data.get("comment", {}) #{"user":str(user_id), "created":str(datetime.datetime.utc()), "title":"", "content":""}
                        if len(comment) != 0:
                            record.comments.append(comment)
                            record.save()
                            return fk.Response('Projject comment posted', status.HTTP_200_OK)
                        else:
                            return fk.redirect('http://0.0.0.0:5000/error-400/')
                    else:
                        return fk.redirect('http://0.0.0.0:5000/error-415/')
                else:
                    return fk.redirect('http://0.0.0.0:5000/error-401/?action=remove_failed')
        else:
            return fk.redirect('http://0.0.0.0:5000/error-401/?action=remove_denied')
    else:
       return fk.redirect('http://0.0.0.0:5000/error-405/') 
开发者ID:gitter-badger,项目名称:corr,代码行数:35,代码来源:record_cloud.py

示例6: file_add

def file_add(hash_session, record_id):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/record/file/upload/<record_id>")
    if not created:
        traffic.interactions += 1 
        traffic.save()
    user_model = UserModel.objects(session=hash_session).first()
    if user_model is None:
        return fk.redirect('http://0.0.0.0:5000/?action=update_denied')
    else:    
        if fk.request.method == 'POST':
            infos = {}
            try:
                record = RecordModel.objects.with_id(record_id)
            except:
                print str(traceback.print_exc())
            if record is None:
                return fk.redirect('http://0.0.0.0:5000/error-204/')
            else:
                if fk.request.data:
                    file_model = FileModel.objects.get_or_create(created_at=datetime.datetime.utcnow())
                    infos = json.loads(fk.request.data)
                    relative_path = infos.get("relative_path", "./")
                    group = infos.get("group", "undefined")
                    description = infos.get("description", "")

                    file_model.group = group
                    file_model.description = description

                    if fk.request.files:
                        if fk.request.files['file']:
                            file_obj = fk.request.files['file']

                            if current_user.quota+file_obj.tell() > 5000000000:
                                return fk.make_response("You have exceeded your 5Gb of quota. You will have to make some space.", status.HTTP_403_FORBIDDEN)
                            else:
                                relative_path = "%s%s"%(relative_path, file_obj.filename)
                                location = str(user_model.id)+"-"+str(record.id)+"_%s"%file_obj.filename

                                try:
                                    uploaded = upload_file(user_model, file_obj)
                                    if uploaded:
                                        file_model.relative_path = relative_path
                                        file_model.location = location
                                        today = datetime.date.today()
                                        (stat, created) = StatModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), interval="%s_%s_%s_0_0_0-%s_%s_%s_23_59_59"%(today.year, today.month, today.day, today.year, today.month, today.day), category="storage", periode="daily")
                                        if not created:
                                            stat.traffic += file_obj.tell()
                                            stat.save()
                                            file_model.save()
                                            return fk.make_response("File uploaded with success.", status.HTTP_200_OK)
                                        else:
                                            return fk.make_response("Could not create storage states.", status.HTTP_500_INTERNAL_SERVER_ERROR)
                                    else:
                                        file_model.delete()
                                        return fk.make_response("Could not upload the file.", status.HTTP_500_INTERNAL_SERVER_ERROR)
                                except Exception, e:
                                    return fk.make_response(str(traceback.print_exc()), status.HTTP_400_BAD_REQUEST)
                    else:
                        return fk.make_response("Missing mandatory fields.", status.HTTP_400_BAD_REQUEST)
        else:
开发者ID:gitter-badger,项目名称:corr,代码行数:60,代码来源:record_cloud.py

示例7: record_view

def record_view(hash_session, record_id):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/record/view/<record_id>")
    if not created:
        traffic.interactions += 1 
        traffic.save()
        
    if fk.request.method == 'GET':
        current_user = UserModel.objects(session=hash_session).first()
        print fk.request.path
        if current_user is not None:
            try:
                record = RecordModel.objects.with_id(record_id)
            except:
                print str(traceback.print_exc())
            if record is None:
                return fk.redirect('http://0.0.0.0:5000/error-204/')
            else:
                if record.project.owner == current_user:
                    return fk.Response(record.to_json(), mimetype='application/json')
                else:
                    return fk.redirect('http://0.0.0.0:5000/error-401/?action=view_failed')
        else:
            return fk.redirect('http://0.0.0.0:5000/error-401/?action=view_denied')
    else:
        return fk.redirect('http://0.0.0.0:5000/error-405/')      
开发者ID:gitter-badger,项目名称:corr,代码行数:25,代码来源:record_cloud.py

示例8: project_dashboard

def project_dashboard(hash_session):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/dashboard/projects")
    if not created:
        traffic.interactions += 1 
        traffic.save()
        
    if fk.request.method == 'GET':
        current_user = UserModel.objects(session=hash_session).first()
        print fk.request.path
        if current_user is None:
            return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_denied')
        else:
            allowance = current_user.allowed("%s%s"%(fk.request.headers.get('User-Agent'),fk.request.remote_addr))
            print "Allowance: "+allowance
            if allowance == hash_session:
                projects = ProjectModel.objects(owner=current_user).order_by('+created_at')
                summaries = []
                for p in projects:
                    project = {"project":json.loads(p.summary_json())}
                    records = RecordModel.objects(project=p)
                    project["activity"] = {"number":len(records), "records":[{"id":str(record.id), "created":str(record.created_at), "updated":str(record.updated_at), "status":str(record.status)} for record in records]}
                    summaries.append(project)
                return fk.Response(json.dumps({'number':len(summaries), 'projects':summaries}, sort_keys=True, indent=4, separators=(',', ': ')), mimetype='application/json')
            else:
                return fk.redirect('http://0.0.0.0:5000/error-401/?action=dashboard_failed')
    else:
        return fk.redirect('http://0.0.0.0:5000/error-405/')
开发者ID:gitter-badger,项目名称:corr,代码行数:27,代码来源:dashboard_cloud.py

示例9: record_remove

def record_remove(hash_session, record_id):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/record/remove/<record_id>")
    if not created:
        traffic.interactions += 1 
        traffic.save()
        
    if fk.request.method == 'DELETE':
        current_user = UserModel.objects(session=hash_session).first()
        print fk.request.path
        if current_user is not None:
            try:
                record = RecordModel.objects.with_id(record_id)
            except:
                print str(traceback.print_exc())
            if record is None:
                return fk.redirect('http://0.0.0.0:5000/error-204/')
            else:
                if record.project.owner == current_user:
                    delete_record_files(record)
                    record.delete()
                    return fk.Response('Record removed', status.HTTP_200_OK)
                else:
                    return fk.redirect('http://0.0.0.0:5000/error-401/?action=remove_failed')
        else:
            return fk.redirect('http://0.0.0.0:5000/error-401/?action=remove_denied')
    else:
       return fk.redirect('http://0.0.0.0:5000/error-405/') 
开发者ID:gitter-badger,项目名称:corr,代码行数:27,代码来源:record_cloud.py

示例10: check_admin

def check_admin(token):
    user_model = UserModel.objects(api_token=token).first()
    if user_model == None:
        return None
    else:
        print user_model.group
        return user_model if user_model.group == "admin" else None
开发者ID:wd15,项目名称:corr,代码行数:7,代码来源:__init__.py

示例11: query_basic

def query_basic(words, page, filtr, current_user):
    filtrs = filter2filters(filtr)
    raw = []
    if "user" not in filtrs:
        raw.extend([u for u in UserModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words)])
        # _users = UserModel.objects(Q(email__in=words)|Q(email__in=words)|)
        # _users_P = ProfileModel.objects()
        pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw))
    if "tool" not in filtrs:
        raw.extend([u for u in ApplicationModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words)])
        pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw))
    if "project" not in filtrs:
        raw.extend([u for u in ProjectModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and (u.access == 'public' or current_user and (current_user == u.owner or current_user.group == "admin"))])

        pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw))
    if "record" not in filtrs:
        raw.extend([u for u in RecordModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and (u.access == 'public' or (current_user and u.project) and (current_user == u.project.owner or current_user.group == "admin"))])
        pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw))
    if "diff" not in filtrs:
        raw.extend([u for u in DiffModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and ((u.record_from.access == 'public' and u.record_to.access == 'public') or (current_user and (current_user.group == "admin" or current_user == u.record_from.project.owner or current_user == u.record_to.project.owner)))])
        pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw))
    if "env" not in filtrs:
        raw.extend([u for u in EnvironmentModel.objects().order_by('+created_at') if all(w in str(u.extended()).lower() for w in words) and (len(ProjectModel.objects(history=str(u.id))) > 0 and (ProjectModel.objects(history=str(u.id))[0].access == 'public' or current_user and (current_user == ProjectModel.objects(history=str(u.id))[0].owner or current_user.group == "admin")))])
        pagination_logs.append("{0} -- query_basic: {1}".format(datetime.datetime.utcnow(), raw))
    return raw2dict(raw, page)
开发者ID:usnistgov,项目名称:corr,代码行数:25,代码来源:__init__.py

示例12: tearDown

 def tearDown(self):
     # Delete all documents
     # Stop mongodb instance.
     for traffic in TrafficModel.objects():
       traffic.delete()
     for stat in StatModel.objects():
       stat.delete()
     for bundle in BundleModel.objects():
       bundle.delete()
     for version in VersionModel.objects():
       version.delete()
     for user in UserModel.objects():
       user.delete()
     for file in FileModel.objects():
       file.delete()
     for profile in ProfileModel.objects():
       profile.delete()
     for message in MessageModel.objects():
       message.delete()
     for project in ProjectModel.objects():
       project.delete()
     for comment in CommentModel.objects():
       comment.delete()
     for application in ApplicationModel.objects():
       application.delete()
     for access in AccessModel.objects():
       access.delete()
     for environment in EnvironmentModel.objects():
       environment.delete()
     for record in RecordModel.objects():
       record.delete()
     for record in RecordBodyModel.objects():
       record.delete()
     for diff in DiffModel.objects():
       diff.delete()
开发者ID:usnistgov,项目名称:corr,代码行数:35,代码来源:test_models.py

示例13: user_logout

def user_logout(hash_session):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/user/logout/<hash_session>")
    if not created:
        traffic.interactions += 1 
        traffic.save()
        
    if fk.request.method == 'GET':
        user_model = UserModel.objects(session=hash_session).first()
        print fk.request.path
        if user_model is None:
            return fk.redirect('http://0.0.0.0:5000/?action=logout_denied')
        else:
            # print "Connected_at: %s"%str(user_model.connected_at)
            allowance = user_model.allowed("%s%s"%(fk.request.headers.get('User-Agent'),fk.request.remote_addr))
            print "Allowance: "+allowance
            # print "Connected_at: %s"%str(user_model.connected_at)
            if allowance == hash_session:
                # user_model.connected_at = datetime.datetime.utcnow()
                # user_model.save()
                user_model.renew("%sLogout"%(fk.request.headers.get('User-Agent')))
                # return fk.redirect('http://0.0.0.0:5000/?action=logout_success')
                return fk.Response('Logout succeed', status.HTTP_200_OK)
            else:
                return fk.redirect('http://0.0.0.0:5000/?action=logout_failed')
    else:
        return fk.make_response('Method not allowed.', status.HTTP_405_METHOD_NOT_ALLOWED)
开发者ID:gitter-badger,项目名称:corr,代码行数:26,代码来源:user_cloud.py

示例14: diff_view

def diff_view(hash_session, diff_id):
    (traffic, created) = TrafficModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), service="cloud", endpoint="/private/diff/view/<diff_id>")
    if not created:
        traffic.interactions += 1 
        traffic.save()
        
    if fk.request.method == 'GET':
        current_user = UserModel.objects(session=hash_session).first()
        print fk.request.path
        if current_user is not None:
            try:
                diff = DiffModel.objects.with_id(diff_id)
            except:
                print str(traceback.print_exc())
            if diff is None:
                return fk.redirect('http://0.0.0.0:5000/error-204/')
            else:
                # Let's allow anybody to be able to see a diff from a search or other.
                # if diff.creator == current_user or diff.target == current_user:
                return fk.Response(diff.to_json(), mimetype='application/json')
                # else:
                #     return fk.redirect('http://0.0.0.0:5000/error-401/?action=view_failed')
        else:
            return fk.redirect('http://0.0.0.0:5000/error-401/?action=view_denied')
    else:
        return fk.redirect('http://0.0.0.0:5000/error-405/')      
开发者ID:gitter-badger,项目名称:corr,代码行数:26,代码来源:diff_cloud.py

示例15: register

    def register(self, email, password, fname, lname, mname):
        """Registration handler.
            Returns:
                User account registered.
        """
        from corrdb.common.models import UserModel
        account = None
        hash_pwd = hashlib.sha256(('CoRRPassword_%s'%password).encode("ascii")).hexdigest()
        if self.type == 'api-token':
            pass
        else:
            if self.type == 'mongodb':
                account = UserModel.objects(email=email).first()
            elif self.type == 'stormpath':
                try:
                    _account = application.authenticate_account(
                        email,
                        password,
                    ).account
                except:
                    _account = None
                if _account != None:
                    account = UserModel.objects(email=email).first()
            if account is None:
                if self.type == 'stormpath':
                    failure = self.create_account(email, password, fname, lname, mname)[0] is None
                    account = UserModel.objects(email=email).first()
                    if account is None:
                        (account, created) = UserModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), email=email, group='user', api_token=hashlib.sha256(('CoRRToken_%s_%s'%(email, str(datetime.datetime.utcnow()))).encode("ascii")).hexdigest())
                    if failure:
                        account.password = hash_pwd
                        account.save()
                if self.type == 'mongodb':
                    account = UserModel.objects(email=email).first()
                    if account is None:
                        (account, created) = UserModel.objects.get_or_create(created_at=str(datetime.datetime.utcnow()), email=email, group='user', api_token=hashlib.sha256(('CoRRToken_%s_%s'%(email, str(datetime.datetime.utcnow()))).encode("ascii")).hexdigest())
                    account.password = hash_pwd
                    account.save()
                account.save()
                return True, account
            else:
                return False, account

        return False, account
开发者ID:faical-yannick-congo,项目名称:corr,代码行数:44,代码来源:access_manager.py


注:本文中的corrdb.common.models.UserModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。