def post(self, encoded_email=""): """ Get fields from POST dict """ if not self.form.validate(): logging.info("didn't validate") return self.get(encoded_email) username = self.form.username.data.lower() email = utils.decode(encoded_email) password = self.form.password.data.strip() # Password to SHA512 password = utils.hashing(password, config.salt) # gravatar goodness email = utils.decode(encoded_email) gravatar_url = "http://en.gravatar.com/%s.json" % hashlib.md5(email.lower()).hexdigest() try: data = json.load(urllib2.urlopen(gravatar_url)) firstname = data['entry'][0]['name']['givenName'] lastname = data['entry'][0]['name']['familyName'] gravatar_url = data['entry'][0]['photos'][0]['value'] country = get_territory_from_ip(self) except: firstname = "" lastname = "" gravatar_url = "" country = get_territory_from_ip(self) logging.info("no data pulled from gravatar") # Passing password_raw=password so password will be hashed # Returns a tuple, where first value is BOOL. # If True ok, If False no new user is created unique_properties = ['username', 'email'] auth_id = "own:%s" % username user = self.auth.store.user_model.create_user( auth_id, unique_properties, password_raw=password, username=username, name=firstname, last_name=lastname, email=email, ip=self.request.remote_addr, country=country, gravatar_url=gravatar_url, activated=True ) if not user[0]: #user is a tuple if "username" in str(user[1]): message = _('Sorry, The username %s is already registered.' % '<strong>{0:>s}</strong>'.format(username) ) elif "email" in str(user[1]): message = _('Sorry, The email %s is already registered.' % '<strong>{0:>s}</strong>'.format(email) ) else: message = _('Sorry, The user is already registered.') self.add_message(message, 'error') return self.redirect_to('register', encoded_email=encoded_email) else: # If the user didn't register using registration form ??? db_user = self.auth.get_user_by_password(user[1].auth_ids[0], password) message = _('Welcome %s, you are now logged in. Please fill out the rest of your profile!' % '<strong>{0:>s}</strong>'.format(username) ) self.add_message(message, 'success') return self.redirect_to('edit-profile')
def get(self, user_id, encoded_email, token): verify = models.User.get_by_auth_token(int(user_id), token) email = utils.decode(encoded_email) if verify[0] is None: self.add_message('There was an error or the link is outdated. Please copy and paste the link from your email.', 'warning') self.redirect_to('home') else: # save new email user = verify[0] user.email = email user.put() # delete token models.User.delete_auth_token(int(user_id), token) # add successful message and redirect self.add_message("Your email has been successfully updated!", "success") self.redirect_to('edit-profile')
def get(self, encoded_email): try: email = utils.decode(encoded_email) user = models.User.get_by_email(email) if (user.activated == False): # send email subject = config.app_name + " Account Verification Email" encoded_email = utils.encode(email) confirmation_url = self.uri_for("account-activation", encoded_email=encoded_email, _full=True) # load email's template template_val = { "app_name": config.app_name, "username": user.username, "confirmation_url": confirmation_url, "support_url": self.uri_for("contact", _full=True) } body_path = "emails/account_activation.txt" body = self.jinja2.render_template(body_path, **template_val) email_url = self.uri_for('taskqueue-send-email') taskqueue.add(url=email_url, params={ 'to': str(email), 'subject': subject, 'body': body, }) message = _('The verification email has been resent to') + " " + str(email) + ". " +\ _('Please check your email to activate your account') self.add_message(message, "success") return self.redirect_to('home') else: message = _('Your account has been activated') + ". " +\ _('Please login to your account') self.add_message(message, "warning") return self.redirect_to('home') except (KeyError, AttributeError), e: message = _('Sorry') + ". " + _('Some error occurred') + "." self.add_message(message, "error") return self.redirect_to('home')
def get(self, encoded_email): try: email = utils.decode(encoded_email) user = models.User.get_by_email(email) if (user.activated == False): # send email subject = config.app_name + " Account Verification Email" encoded_email = utils.encode(email) confirmation_url = self.uri_for("account-activation", encoded_email = encoded_email, _full = True) # load email's template template_val = { "app_name": config.app_name, "username": user.username, "confirmation_url": confirmation_url, "support_url": self.uri_for("contact", _full=True) } body_path = "emails/account_activation.txt" body = self.jinja2.render_template(body_path, **template_val) email_url = self.uri_for('taskqueue-send-email') taskqueue.add(url = email_url, params={ 'to': str(email), 'subject' : subject, 'body' : body, }) message = _('The verification email has been resent to') + " " + str(email) + ". " +\ _('Please check your email to activate your account') self.add_message(message, "success") return self.redirect_to('home') else: message = _('Your account has been activated') + ". " +\ _('Please login to your account') self.add_message(message, "warning") return self.redirect_to('home') except (KeyError, AttributeError), e: message = _('Sorry') + ". " + _('Some error occured') + "." self.add_message(message, "error") return self.redirect_to('home')
def get(self, user_id, encoded_email, token): verify = models.User.get_by_auth_token(int(user_id), token) email = utils.decode(encoded_email) if verify[0] is None: message = _('The URL you tried to use is either incorrect or no longer valid.') self.add_message(message, 'warning') self.redirect_to('home') else: # save new email user = verify[0] user.email = email user.put() # delete token models.User.delete_auth_token(int(user_id), token) # add successful message and redirect message = _('Your email has been successfully updated.') self.add_message(message, 'success') self.redirect_to('edit-profile')
def get(self, encoded_email): try: email = utils.decode(encoded_email) user = models.User.get_by_email(email) # activate the user's account user.activated = True user.put() message = _('Congratulations') + "! " + _('Your account') + " (@" + user.username + ") " +\ _('has just been activated') + ". " + _('Please login to your account') self.add_message(message, "success") self.redirect_to('login') except (AttributeError, KeyError, InvalidAuthIdError), e: message = _('Unexpected error activating '\ 'account') + " " + '{0:>s}.'.format(user.username) self.add_message(message, 'error') self.abort(403)
def get(self, user_id, encoded_email, token): verify = models.User.get_by_auth_token(int(user_id), token) email = utils.decode(encoded_email) if verify[0] is None: self.add_message( 'There was an error or the link is outdated. Please copy and paste the link from your email.', 'warning') self.redirect_to('home') else: # save new email user = verify[0] user.email = email user.put() # delete token models.User.delete_auth_token(int(user_id), token) # add successful message and redirect self.add_message("Your email has been successfully updated!", "success") self.redirect_to('edit-profile')
def get(self, encoded_email=""): """ Returns a simple HTML form for create a new user """ # gravatar goodness email = utils.decode(encoded_email) gravatar_url = "http://en.gravatar.com/%s.json" % hashlib.md5(email.lower()).hexdigest() try: data = json.load(urllib2.urlopen(gravatar_url)) suggested_username = data['entry'][0]['preferredUsername'] except: suggested_username = "" logging.info("no data pulled from gravatar") if self.user: self.redirect_to('home') #use the suggested username from gravatar params = {"suggested_username": suggested_username} return self.render_template('user/register.html', **params)
def get(self, encoded_email=""): """ Returns a simple HTML form for create a new user """ # gravatar goodness email = utils.decode(encoded_email) gravatar_url = "http://en.gravatar.com/%s.json" % hashlib.md5( email.lower()).hexdigest() try: data = json.load(urllib2.urlopen(gravatar_url)) suggested_username = data['entry'][0]['preferredUsername'] except: suggested_username = "" logging.info("no data pulled from gravatar") if self.user: self.redirect_to('home') #use the suggested username from gravatar params = {"suggested_username": suggested_username} return self.render_template('user/register.html', **params)
def get(self, user_id, encoded_email, token): verify = models.User.get_by_auth_token(int(user_id), token) email = utils.decode(encoded_email) if verify[0] is None: message = _( 'The URL you tried to use is either incorrect or no longer valid.' ) self.add_message(message, 'warning') self.redirect_to('home') else: # save new email user = verify[0] user.email = email user.put() # delete token models.User.delete_auth_token(int(user_id), token) # add successful message and redirect message = _('Your email has been successfully updated.') self.add_message(message, 'success') self.redirect_to('edit-profile')
def post(self, encoded_email=""): """ Get fields from POST dict """ if not self.form.validate(): logging.info("didn't validate") return self.get(encoded_email) username = self.form.username.data.lower() email = utils.decode(encoded_email) password = self.form.password.data.strip() # Password to SHA512 password = utils.hashing(password, config.salt) # gravatar goodness email = utils.decode(encoded_email) gravatar_url = "http://en.gravatar.com/%s.json" % hashlib.md5( email.lower()).hexdigest() try: data = json.load(urllib2.urlopen(gravatar_url)) firstname = data['entry'][0]['name']['givenName'] lastname = data['entry'][0]['name']['familyName'] gravatar_url = data['entry'][0]['photos'][0]['value'] country = get_territory_from_ip(self) except: firstname = "" lastname = "" gravatar_url = "" country = get_territory_from_ip(self) logging.info("no data pulled from gravatar") # Passing password_raw=password so password will be hashed # Returns a tuple, where first value is BOOL. # If True ok, If False no new user is created unique_properties = ['username', 'email'] auth_id = "own:%s" % username user = self.auth.store.user_model.create_user( auth_id, unique_properties, password_raw=password, username=username, name=firstname, last_name=lastname, email=email, ip=self.request.remote_addr, country=country, gravatar_url=gravatar_url, activated=True) if not user[0]: #user is a tuple if "username" in str(user[1]): message = _('Sorry, The username %s is already registered.' % '<strong>{0:>s}</strong>'.format(username)) elif "email" in str(user[1]): message = _('Sorry, The email %s is already registered.' % '<strong>{0:>s}</strong>'.format(email)) else: message = _('Sorry, The user is already registered.') self.add_message(message, 'error') return self.redirect_to('register', encoded_email=encoded_email) else: # If the user didn't register using registration form ??? db_user = self.auth.get_user_by_password(user[1].auth_ids[0], password) message = _( 'Welcome %s, you are now logged in. Please fill out the rest of your profile!' % '<strong>{0:>s}</strong>'.format(username)) self.add_message(message, 'success') return self.redirect_to('edit-profile')
def parse_files(self, versionfile, xmlfile): self.gui.setBusy(self.window_main) dversion = open(versionfile).readline() dversion = float(dversion) print "version:", dversion rec = self.actions.get_iugversion()[0] id = rec['id'] lversion = rec['version'] print id, lversion , lversion < dversion,lversion , dversion if lversion < dversion : self.actions.edit_iugversion({'version': dversion,'id': id, 'version_date': get_current_date()}) xFile = XML2obj(xmlfile) xobj = xFile.get_python_from_xml() game = xobj.game for n in game: exist = self.actions.get_categories({'categoryname':decode(n.category)}) if not exist: self.actions.add_category({'categoryname':decode(n.category)}) cat = self.actions.get_categories({'categoryname':decode(n.category)})[0] game_exist = self.actions.get_games({'game': decode(n.name)}) print decode(n.description) if not game_exist : game_dict=dict({'category': cat['id'], 'game': decode(n.name), 'description': decode(n.description), 'image_url': decode(n.image_url), 'image_file': get_file_name(decode(n.image_url)), 'requires': decode(n.requires), 'download_url':decode(n.download_url), 'download_type':decode(n.download_type), 'file_size':decode(n.file_size), 'website': decode(n.site), 'deb_filename':decode(n.deb_filename), 'install_command':decode(n.install_command), 'version':decode(n.version), 'file_size': decode(n.file_size), 'rate':decode(n.rate)}) self.actions.add_game(game_dict); else: game_dict=dict({'category': cat['id'], 'id' : game_exist[0]['id'], 'game': decode(n.name), 'description': decode(n.description), 'image_url': decode(n.image_url), 'image_file': get_file_name(decode(n.image_url)), 'requires': decode(n.requires), 'download_url':decode(n.download_url), 'download_type':decode(n.download_type), 'file_size':decode(n.file_size), 'website': decode(n.site), 'deb_filename':decode(n.deb_filename), 'install_command':decode(n.install_command), 'version':decode(n.version), 'file_size': decode(n.file_size), 'rate':decode(n.rate)}) self.actions.edit_game(game_dict) self.gui.setBusy(self.window_main, True)
if len(sys.argv) != 3: print print "\tUsage: python %s <input-file> <queue1,queue2..>" % sys.argv[0] print print "\tExample: python %s /tmp/events.txt events-queue" % sys.argv[0] print exit() file = open(sys.argv[1], 'r') queues = sys.argv[2].split(',') pipeline = Pipeline(None, queues) for line in file: line = decode(line) try: event = Event.from_unicode(line) except: print "ERROR - lines from file needs to follow Event format" for key in event.keys(): value = event.value(key) event.clear(key) key = key.replace(' ','_') event.add(key, value) time.sleep(0.01) pipeline.send(decode(event))