示例#1
0
 def run(self):
     self.logger.info(u"Добавление нового пользователя:")
     self.logger.info(u'=' * 50)
     username = get_single(u'username: '******'password: '******'не удалось создать пользователя')
         exit(-1)
示例#2
0
 def run(self):
     self.logger.info(u"Добавление нового пользователя:")
     self.logger.info(u'=' * 50)
     username = get_single(u'username: '******'password: '******'не удалось создать пользователя')
         exit(-1)
示例#3
0
def login_external(social_network=None, next_page=""):
    class MyResp(Response):
        def set_cookie(self, key, value='', max_age=None, expires=None,
                       path='/', domain=None, secure=None, httponly=False):
            self.__name = key
            self.__val = value
            super(MyResp, self).set_cookie(key, value, max_age, expires, path, domain, secure, httponly)

    try:
        code = request.args['code']
    except Exception:
        if 'error' in request.args:
            html = u"""<html><head></head><body><script>window.location.href = "/";</script></body></html>"""
            my_resp = MyResp(html, status=200, content_type="text/html; charset=utf-8")
            return my_resp
        raise errors.InvalidParameterValue('code')

    if social_network not in ('facebook', 'vk', 'google'):
        raise errors.InvalidParameterValue('social_network')

    backend = SocialServiceBackends.backends.get(social_network)
    if not backend:
        raise errors.InvalidParameterValue('social_network')

    config = current_app.config

    if backend:
        if '?' in next_page:
            next_page = next_page.split('?')[0]
        current_app.logger.debug(u"2 redirect url: %s" % next_page)
        access_token, ext_data = backend.get_token(code, config, next_page=next_page)
        if not access_token:
            raise errors.SocialAuthError()

        user_data = backend.get_user_data(config, access_token)
        social_uid = user_data.get('id')
        if not social_uid:
            raise errors.SocialAuthError()
        social_service_user_link = backend.get_user_link(unicode(social_uid))
        if social_service_user_link:
            user = social_service_user_link.user
        else:
            ext_data = ext_data or {}
            if 'email' not in ext_data:
                ext_data = backend.get_user_data(config, access_token)
            user, user_profile = UserManager.create_user(access_token, "", ext_data.get('email', ""), "", "", "", "",
                                                            social_network, email_is_social=True)

        old_user_id = current_user.id if (
            current_user and not current_user.is_anonymous and current_user.temporal) else None
        if old_user_id:
            new_user_id = user.id
            change_account_data_owner(old_user_id, new_user_id)

        google_client_id = request.cookies.get('_ga_cid')
        if google_client_id and not user.temporal:
            metrics.update_user_info(user, google_client_id=google_client_id)
        login_user(user)
        user.last_login_date = datetime.utcnow()

        my_resp = MyResp()
        current_app.session_interface.save_session(current_app, flask.session, my_resp)
        # noinspection PyUnresolvedReferences
        html = u"""
        <html>
        <head></head>
        <body>
        <script>
        window.location.href = "/%s";
        </script>
        </body>
        </html>
    """ % next_page
        my_resp = MyResp(html, status=200, content_type="text/html; charset=utf-8")
        return my_resp

    return {"result": None}