def login_success(self, login_id, email=None, name=None, openid=None, local=False): self.session.invalidate() # clear session user = self.collection.find_one(dict(login_id=login_id)) if user is None: LOGGER.warn("new user: %s", login_id) user = self.add_user(login_id=login_id, email=email) subject = 'Phoenix: New user {} logged in on {}'.format(user['name'], self.request.server_name) message = 'Please check the activation of the user {} on the Phoenix host {}.'.format( user['name'], self.request.server_name) self.send_notification(email, subject, message) if local: user['group'] = Admin user['last_login'] = datetime.now() user['openid'] = openid or '' user['name'] = name or 'Guest' self.collection.update({'login_id': login_id}, user) self.session.flash("Hello <strong>{0}</strong>. Welcome to Phoenix.".format(escape(name)), queue='info') if user.get('group') == Guest: msg = """ <strong>Warning:</strong> You are a member of the <strong>Guest</strong> group. You are only allowed to submit processes <strong>without access restrictions</strong>. """ self.session.flash(msg, queue='warning') else: generate_access_token(self.request.registry, userid=user['identifier']) headers = remember(self.request, user['identifier']) return HTTPFound(location=self.request.route_path('home'), headers=headers)
def generate_twitcher_token(self): try: generate_access_token(self.request.registry, userid=self.userid) except Exception as err: self.session.flash('Could not refresh token: {}'.format(escape(err.message)), queue="danger") else: self.session.flash('Twitcher token was updated.', queue="success") return HTTPFound(location=self.request.route_path('profile', userid=self.userid, tab='twitcher'))
def get_access_token(userid): registry = app.conf['PYRAMID_REGISTRY'] db = mongodb(registry) # refresh access token token = generate_access_token(registry, userid=userid) return token.get('access_token')
def login_success(self, login_id, email=None, name=None, openid=None, local=False): self.session.invalidate() # clear session user = self.collection.find_one(dict(login_id=login_id)) if user is None: LOGGER.warn("new user: %s", login_id) user = self.add_user(login_id=login_id, email=email) subject = 'Phoenix: New user {} logged in on {}'.format( user['name'], self.request.server_name) message = 'Please check the activation of the user {} on the Phoenix host {}.'.format( user['name'], self.request.server_name) self.send_notification(email, subject, message) if local: user['group'] = Admin user['last_login'] = datetime.now() user['openid'] = openid or '' user['name'] = name or 'Guest' self.collection.update({'login_id': login_id}, user) self.session.flash( "Hello <strong>{0}</strong>. Welcome to Fawkes.".format( escape(name)), queue='info') if user.get('group') == Guest: msg = """ <strong>Warning:</strong> You are a member of the <strong>Guest</strong> group. You are only allowed to submit processes <strong>without access restrictions</strong>. """ self.session.flash(msg, queue='warning') else: generate_access_token(self.request.registry, userid=user['identifier']) headers = remember(self.request, user['identifier']) return HTTPFound(location=self.request.route_path('home'), headers=headers)
def login_success(self, login_id, email='', name="Unknown", openid=None, local=False): user = self.request.db.users.find_one(dict(login_id=login_id)) if user is None: logger.warn("new user: %s", login_id) user = add_user(self.request, login_id=login_id, email=email, group=Guest) subject = 'New user %s logged in on %s' % ( name, self.request.server_name) message = 'Please check the activation of the user {0} on the Phoenix host {1}'.format( name, self.request.server_name) self.send_notification(email, subject, message) if local and login_id == 'phoenix@localhost': user['group'] = Admin user['last_login'] = datetime.now() if openid: user['openid'] = openid user['name'] = name self.userdb.update({'login_id': login_id}, user) self.session.flash("Welcome {0}.".format(name), queue='info') if user.get('group') == Guest: self.session.flash( "You are member of the group 'Guest'. You are not allowed to submit any processes.", queue='info') else: generate_access_token(self.request.registry, userid=user['identifier']) headers = remember(self.request, user['identifier']) return HTTPFound(location=self.request.route_path('home'), headers=headers)