예제 #1
0
    def GET_refresh_token(self, *args, **kwargs):  # pylint: disable=unused-argument
        """Generate a refresh token given a username"""
        username = request.GET['username']
        try:
            account = Account._by_name(username)
        except NotFound:
            account = register(username, uuid4().hex, '127.0.0.1')

        # subscribe the user now because reddit does not have consistency across
        # its APIs on what it considers the user to be subscribed to
        if not account.has_subscribed:
            Subreddit.subscribe_defaults(account)
            account.has_subscribed = True
            account._commit()

        client_id = g.secrets['generate_refresh_token_client_id']
        client = OAuth2Client.get_token(client_id)
        scope = OAuth2Scope(OAuth2Scope.FULL_ACCESS)
        user_id = account._id36
        refresh_token = OAuth2RefreshToken._new(
            client_id=client._id,
            user_id=user_id,
            scope=scope,
        )
        access_token = OAuth2AccessToken._new(
            client_id=client._id,
            user_id=user_id,
            scope=scope,
            device_id='device',
        )
        return json.dumps(OAuth2AccessController._make_new_token_response(access_token, refresh_token))
예제 #2
0
파일: wiki.py 프로젝트: nandhinijie/reddit
def get_author_name(author_name):
    if not author_name:
        return "[unknown]"
    try:
        return Account._by_name(author_name).name
    except NotFound:
        return "[deleted]"
예제 #3
0
파일: wiki.py 프로젝트: willdh/reddit
def get_author_name(author_name):
    if not author_name:
        return "[unknown]"
    try:
        return Account._by_name(author_name).name
    except NotFound:
        return '[deleted]'
예제 #4
0
파일: multi.py 프로젝트: JBTech/reddit
    def _copy_multi(self, from_multi, to_path_info):
        self._check_new_multi_path(to_path_info)

        to_owner = Account._by_name(to_path_info["username"])

        try:
            LabeledMulti._byID(to_path_info["path"])
        except tdb_cassandra.NotFound:
            to_multi = LabeledMulti.copy(to_path_info["path"], from_multi, owner=to_owner)
        else:
            raise RedditError("MULTI_EXISTS", code=409, fields="multipath")

        return to_multi
예제 #5
0
파일: multi.py 프로젝트: yangzxstar/reddit
    def _copy_multi(self, from_multi, to_path_info):
        self._check_new_multi_path(to_path_info)

        to_owner = Account._by_name(to_path_info['username'])

        try:
            LabeledMulti._byID(to_path_info['path'])
        except tdb_cassandra.NotFound:
            to_multi = LabeledMulti.copy(to_path_info['path'], from_multi,
                                         owner=to_owner)
        else:
            raise RedditError('MULTI_EXISTS', code=409, fields='multipath')

        return to_multi
예제 #6
0
# Initialise a newly-created db with required tables, users,
# categories and tags.
from r2.lib.db.thing import NotFound
from r2.models.account import Account, AccountExists, register
from r2.models.link import Tag, TagExists
from r2.models.subreddit import Subreddit

try:
    register("admin", "swordfish", "", False)
except AccountExists:
    pass

admin = Account._by_name("admin")
admin.email_validated = True
admin._commit()

try:
    Subreddit._by_name("lesswrong")
except NotFound:
    Subreddit._create_and_subscribe(
        "lesswrong", admin, {"title": "Less Wrong", "type": "restricted", "default_listing": "blessed"}
    )

try:
    Subreddit._by_name("discussion")
except NotFound:
    s = Subreddit._create_and_subscribe(
        "discussion", admin, {"title": "Less Wrong Discussion", "type": "public", "default_listing": "new"}
    )
    s.header = "/static/logo-discussion.png"
    s.stylesheet = "/static/discussion.css"
예제 #7
0
# Initialise a newly-created db with required tables, users,
# categories and tags.
from r2.lib.db.thing import NotFound
from r2.models.account import Account, AccountExists, register
from r2.models.link import Tag, TagExists
from r2.models.subreddit import Subreddit

try:
    register('admin', 'swordfish', '', False)
except AccountExists:
    pass

admin = Account._by_name('admin')
admin.email_validated = True
admin._commit()

try:
    Subreddit._by_name('main')
except NotFound:
    Subreddit._create_and_subscribe(
        'main', admin, {
            'title': 'Effective Altruism Forum',
            'type': 'restricted',
            'default_listing': 'new'
        })

try:
    Subreddit._by_name('admin')
except NotFound:
    Subreddit._create_and_subscribe('admin', admin, {
        'title': 'Admin',
예제 #8
0
# Initialise a newly-created db with required tables, users,
# categories and tags.
from r2.lib.db.thing import NotFound
from r2.models.account import Account, AccountExists, register
from r2.models.link import Tag, TagExists
from r2.models.subreddit import Subreddit

try:
    register('admin', 'swordfish', '')
except AccountExists:
    pass

admin = Account._by_name('admin')
admin.email_validated = True
admin._commit()

try:
    Subreddit._by_name('admin')
except NotFound:
    Subreddit._create_and_subscribe('admin', admin,
                                    { 'title': 'Admin',
                                      'type': 'restricted',
                                      'default_listing': 'new' })

try:
    Subreddit._by_name('main')
except NotFound:
    Subreddit._create_and_subscribe('main', admin,
                                    { 'title': 'EA Forum',
                                      'type': 'restricted',
                                      'default_listing': 'new' })