def listuserinfo(): arguments = listuserparser.parse_args() if not arguments.config or not arguments.username: listuserparser.print_usage() else: config_uri = arguments.config setup_logging(config_uri) try: settings = get_appsettings(config_uri, 'factored') except LookupError: settings = get_appsettings(config_uri, 'main') engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) session = DBSession() users = session.query(User).filter_by( username=arguments.username).all() if len(users) > 0: user = users[0] print 'username:%s, secret: %s' % ( user.username, user.secret) print 'bar code url:', get_barcode_image(user.username, user.secret, settings['appname']) else: print '"%s" user not found' % arguments.username
def listuserinfo(): arguments = listuserparser.parse_args() if not arguments.config or not arguments.username: listuserparser.print_usage() else: config_uri = arguments.config setup_logging(config_uri) try: settings = get_appsettings(config_uri, 'factored') except LookupError: settings = get_appsettings(config_uri, 'main') engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) session = DBSession() users = session.query(User).filter_by( username=arguments.username).all() if len(users) > 0: user = users[0] print('username:%s, secret: %s' % (user.username, user.secret)) print( 'bar code url:', get_barcode_image(user.username, user.secret, settings['appname'])) else: print('"%s" user not found' % arguments.username)
def send_code_reminder(self, user): mailer = get_mailer(self.req) code_reminder_settings = \ self.req.registry['settings']['allowcodereminder_settings'].copy() username = user.username message = code_reminder_settings.copy() message['recipients'] = [username] appname = self.req.registry['settings']['appname'] message['body'] = message['body'].replace( '{code}', get_barcode_image(username, user.secret, appname)) mailer.send_immediately(Message(**message))
def send_code_reminder(self, user): mailer = get_mailer(self.req) code_reminder_settings = \ self.req.registry['settings']['allowcodereminder_settings'].copy() username = user.username message = code_reminder_settings.copy() message['recipients'] = [username] appname = self.req.registry['settings']['appname'] message['body'] = message['body'].replace( '{code}', get_barcode_image(username, user.secret, appname)) message['extra_headers'] = {'Message-ID': create_message_id()} mailer.send_immediately(Message(**message))
def add(): arguments = addparser.parse_args() if not arguments.config or not arguments.username: addparser.print_usage() else: config_uri = arguments.config setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) with transaction.manager: username = arguments.username user = create_user(username) print 'barcode url:', get_barcode_image(username, user.secret, settings['appname']) print 'secret:', user.secret
def add(): arguments = addparser.parse_args() if not arguments.config or not arguments.username: addparser.print_usage() else: config_uri = arguments.config setup_logging(config_uri) try: settings = get_appsettings(config_uri, 'factored') except LookupError: settings = get_appsettings(config_uri, 'main') engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) session = DBSession() username = arguments.username user = create_user(username, session) print 'barcode url:', get_barcode_image(username, user.secret, settings['appname']) print 'secret:', user.secret session.commit() session.close()
def add(): arguments = addparser.parse_args() if not arguments.config or not arguments.username: addparser.print_usage() else: config_uri = arguments.config setup_logging(config_uri) try: settings = get_appsettings(config_uri, 'factored') except LookupError: settings = get_appsettings(config_uri, 'main') engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) session = DBSession() username = arguments.username user = create_user(username, session) print('barcode url:', get_barcode_image(username, user.secret, settings['appname'])) print('secret:', user.secret) session.commit() session.close()
def __call__(self): req = self.req if req.method == "POST": if req.POST.get('submit', '') == self.form_button_codereminder \ and self.allowgooglecodereminder: self.validate_submitted = True self.cform.validate() self.cform.errors['code'] = self.error_code_reminder username = self.cform.data['username'] user = self.get_user(username) if 'username' not in self.cform.errors and user is not None: mailer = self.req.registry['mailer'] message = self.googleauthcodereminder_settings.copy() message['recipients'] = [username] message['body'] = message['body'].replace('{code}', get_barcode_image(username, user.secret, self.req.registry['settings']['appname'])) mailer.send(Message(**message)) elif req.POST.get('submit', '') == self.form_button_username: if self.uform.validate(): username = self.uform.data['username'] self.cform.data['username'] = username user = self.get_user(username) if user is None: self.uform.errors['username'] = \ self.error_invalid_username else: self.send_submitted = True self.user_form_submitted_successfully(user) elif req.POST.get('submit', '') == self.form_button_authenticate: self.validate_submitted = True if self.cform.validate(): user = self.get_user(self.cform.data['username']) if user is None: self.cform.errors['code'] = \ self.error_invalid_username_code else: if self.check_code(user): creds = {} creds['repoze.who.userid'] = \ self.cform.data['username'] creds['identifier'] = \ self.req.registry['settings']['auth_tkt'] if self.cform.data['remember']: creds['max_age'] = self.auth_remember_timeout else: creds['max_age'] = self.auth_timeout who_api = self.req.environ['who_api'] headers = who_api.remember(creds) referrer = self.cform.data.get('referrer') if not referrer: referrer = '/' raise HTTPFound(location=referrer, headers=headers) else: self.cform.errors['code'] = self.error_invalid_code self.cform.data['code'] = u'' referrer = self.cform.data.get('referrer', self.uform.data.get('referrer', req.params.get('referrer', ''))) self.uform.data.update({'referrer': referrer}) self.cform.data.update({'referrer': referrer}) return get_context(req, uform=FormRenderer(self.uform), cform=FormRenderer(self.cform), send_submitted=self.send_submitted, validate_submitted=self.validate_submitted, form_button_username=self.form_button_username, form_button_authenticate=self.form_button_authenticate, form_button_codereminder=self.form_button_codereminder, form_title=self.form_title, form_legend=self.form_legend, form_username_label=self.form_username_label, form_username_desc=self.form_username_desc, form_code_label=self.form_code_label, form_code_desc=self.form_code_desc, allowgooglecodereminder=self.allowgooglecodereminder, remember_duration=self.remember_duration)