def get(self): repository = UserRepository() user = repository.get(self.user.id) if user.slack.is_notify(): user.slack.notify_stop() return user.timer.stop()
def post(self): user_id = self.request.get('id') if not user_id: raise error.TaskUnrecoverableException( error.BadRequestException('`id` parameter is not specified')) repository = UserRepository() user = repository.get(user_id) if user is None: raise error.TaskUnrecoverableException( error.NotFoundException('No such user: {}'.format(user_id))) user.timer.stop()
def post(self): user_id = self.request.get('id') if not user_id: raise error.TaskUnrecoverableException( error.BadRequestException('`id` parameter is not specified')) repository = UserRepository() user = repository.get(user_id) if user is None: raise error.TaskUnrecoverableException( error.NotFoundException('No such user: {}'.format(user_id))) repository.add_pomodoro(user) user.timer.stop_after_break() if user.slack.is_notify(): user.slack.notify_end()
def get(self): code = self.request.params.get('code', 'none') state = self.request.params.get('state') check_state(self.session_id, state) provider = OAuth2Session(secret.SLACK_CLIENT_ID, scope=[','.join(AUTH_SCOPE)], redirect_uri=secret.SLACK_USER_REDIRECT_URI) token = provider.fetch_token(TOKEN_URL, client_secret=secret.SLACK_CLIENT_SECRET, code=code) token = token['access_token'] api = infra.slack.API(token) slack_team = api.get_team_info()['team'] repository = UserRepository() user = repository.get(self.user.id) user.slack.update(token, slack_team['name'], slack_team['domain']) self.redirect('/#')
def get(self): code = self.request.params.get('code', 'none') state = self.request.params.get('state') # if not check_state(self.session_id, state): # raise error.ForbiddenException('`state` not matches') provider = OAuth2Session(secret.GOOGLE_CLIENT_ID, scope=GOOGLE_AUTH_SCOPE, redirect_uri=secret.GOOGLE_REDIRECT_URI) provider.fetch_token(GOOGLE_TOKEN_URL, client_secret=secret.GOOGLE_CLIENT_SECRET, code=code) r = provider.get('https://www.googleapis.com/oauth2/v1/userinfo') j = json.loads(r.content) # fetch user by google ID repository = UserRepository() user = repository.get_by_google_id(j['id']) # sing in if user is not None: pass # sing up else: user = repository.new(name=j.get('name'), email=j.get('email'), image=j.get('picture'), google_id=j['id']) self.session['user'] = user.to_json() origin_url = self.session.get('origin_url') if origin_url: self.session['origin_url'] = None self.redirect(str(origin_url)) else: self.redirect('/')
def get(self): repository = UserRepository() user = repository.get(self.user.id) return user.slack.get_channels()