Ejemplo n.º 1
0
    def check_or_create(self, token, auth_type):
        if auth_type == 'github':
            github = Github()
            user_info = github.get_user_info(token)
            user = User.objects(github_id=user_info['id']).first()

            if not user:
                user = User()
                email_github = github.get_email(token)

                user.token_github = token
                user.github = user_info['html_url']
                user.email = email_github[0]
                user.name = user_info['name']
                user.username = user_info['login']
                user.city = user_info['location']
                user.gravatar_id = user_info['gravatar_id']
                user.github_id = user_info['id']

                user.save()
                self.create_auth_session(user.id, token, auth_type)

            return self.create_auth_session(user.id, token, auth_type)
        else:
            return False
Ejemplo n.º 2
0
    def check_or_create(self, token, auth_type):
        if auth_type == 'github':
            github = Github()
            user_info = github.get_user_info(token)
            user = User.objects(github_id=user_info['id']).first()
            
            if not user:
                user = User()
                email_github = github.get_email(token)
                
                user.token_github = token
                user.github = user_info['html_url']
                user.email = email_github[0]
                user.name = user_info['name']
                user.username = user_info['login']
                user.city     = user_info['location']
                user.gravatar_id = user_info['gravatar_id']
                user.github_id =user_info['id']

                user.save()
                self.create_auth_session(user.id, token, auth_type)

            return self.create_auth_session(user.id, token, auth_type)
        else:
            return False
Ejemplo n.º 3
0
def request_to_class(json_request):
    user = User()
    name = json_request.get('name', None)
    information_datas = json_request.get('information', {})
    events_datas = json_request.get('events', [])
    user.name = name
    if information_datas is not None:
        for k, v in information_datas.items():
            if k in user.model['information']:
                user.model['information'][k] = v
    if events_datas is not None:
        for events_data in events_datas:
            event = Event()
            for k, v in events_data.items():
                if k in event.model:
                    event.model[k] = v
            user.events.append(event)
    return user