Exemplo n.º 1
0
async def fetchaccessinfo(req, resp):
    data = await req.media()
    hashdata = backapp.decodeHashID(data['accesshash'])
    if data['accesshash'] in getattr(backapp,
                                     f'validID_{hashdata["access_type"]}')(
                                         backapp.verify_user(data['token'])):
        accessinfo = getattr(backapp,
                             f'get_{hashdata["access_type"]}')(hashdata['ids'],
                                                               0)
        resp.media = {
            'icon': accessinfo['icon'],
            'name': accessinfo[f'{hashdata["access_type"]}_name'],
        }
        if hashdata["access_type"] == 'user':
            resp.media['name'] = accessinfo['nick_name']
            resp.media['description'] = f'@{accessinfo["user_name"]}'
            for k in [
                    'user_name', 'real_name', 'email', 'phone_number',
                    'zipcode', 'address'
            ]:
                resp.media[k] = accessinfo[k]
        elif hashdata["access_type"] == 'project':
            company = backapp.decodeHashID(accessinfo['company_id'])
            if company['access_type'] == 'user':
                resp.media['description'] = 'Private'
            else:
                resp.media['description'] = backapp.get_company(
                    company['ids'], 100)['company_name']
            resp.media['tree'] = accessinfo['tree']
Exemplo n.º 2
0
async def validhashid(req, resp, *, hash_types):
    user_id = backapp.verify_user((await req.media())['token'])
    if hash_types == 'all':
        hash_types = '-'.join(backapp.accessType)
    resp.media = [{
        'type': t,
        'data': getattr(backapp, f'validID_{t}')(user_id)
    } for t in hash_types.split('-')]
Exemplo n.º 3
0
async def calendarprivacylevel(req, resp):
    data = await req.media()
    resp.media = {
        'isValid':
        googleapi.change_calendar_privacy_level(
            backapp.verify_user(data['token']), data['c_id'],
            data['new_level'])
    }
Exemplo n.º 4
0
async def assign(req, resp):
    data = await req.media()
    hashdata = backapp.decodeHashID(data['accesshash'])
    resp.media = {
        'isValid':
        getattr(backapp, f'add_member2{hashdata["access_type"]}')(
            hashdata['ids'], backapp.verify_user(data['token']))
    }
Exemplo n.º 5
0
async def createcompany(req, resp):
    data = await req.media()
    data['admin'] = backapp.verify_user(data.pop('token'))
    data['sub_admin'] = [
        backapp.decodeHashID(e)['ids'] for e in data['sub_admin']
    ]
    data['members'] = [backapp.decodeHashID(e)['ids'] for e in data['members']]
    data.setdefault('icon', '/static/usericons/default.png')
    resp.media = {'isValid': True, 'accesshash': backapp.add_company(data)}
Exemplo n.º 6
0
async def createproject(req, resp):
    data = await req.media()
    data['admin'] = backapp.verify_user(data.pop('token'))
    data['sub_admin'] = []
    data['members'] = [backapp.decodeHashID(e)['ids'] for e in data['members']]
    data.setdefault('icon', '/static/usericons/default.png')
    data['company_id'] = data['tree'].split('/')[0]
    if data['company_id'] == 'private':
        data['company_id'] = backapp.generateHashID(data['admin'], 'user')
    resp.media = {'isValid': True, 'accesshash': backapp.add_project(data)}
Exemplo n.º 7
0
async def signup(req, resp):
    resp.media = backapp.signup(await req.media())

    @api.background.task
    def sendVerificationEmail(user_id):
        # ユーザのメアドに確認のメールを送る
        # これが完了するまではユーザはtmpに登録しておく
        pass

    if resp.media['isValid']:
        sendVerificationEmail(backapp.verify_user(resp.media['token']))
Exemplo n.º 8
0
async def googlecalendar(req, resp):
    data = await req.media()
    credentials = googleapi.googleCalendarAPI_creds(data['code'],
                                                    data['redirect_uri'])

    @api.background.task
    def cred2db(user_id, credentials: googleapi.Credentials):
        googleapi.updateUserCredentials(user_id, credentials)
        googleapi.save_calendar_id(user_id, credentials)
        googleapi.print_calendar_info(credentials)

    cred2db(backapp.verify_user(data['token']), credentials)
    resp.media = {'success': True}
Exemplo n.º 9
0
async def message(req, resp):
    resp.media = {
        'msg':
        backapp.unreadmessage(backapp.verify_user((await
                                                   req.media())['token']))
    }
Exemplo n.º 10
0
async def feedback(req, resp):
    data = await req.media()
    user_id = backapp.verify_user(data['token'])
    feedback_id = backapp.setfeedback(user_id, data['feedback'])
Exemplo n.º 11
0
async def username(req, resp):
    resp.media = {
        'user_name':
        backapp.username(backapp.verify_user((await req.media())['token']))
    }
Exemplo n.º 12
0
async def getmycalendars(req, resp):
    resp.media = {
        'calendarList':
        googleapi.get_all_calendars(
            backapp.verify_user((await req.media())['token']))
    }
Exemplo n.º 13
0
async def hasgoogle(req, resp):
    user_id = backapp.verify_user((await req.media())['token'])
    resp.media = {
        'isValid': user_id is not False and googleapi.hasCredentials(user_id)
    }