def GET(self): db = database.get_db() sess = session.get_session() results = db.where('users', what='username', id=sess.user_id) for row in results: username = row.username return template.ltpl('recover_password/complete', username)
def POST(self): self.form = self.username_form() if self.form.validates(): if self.username_already_exists(self.form['username'].value): return template.ltpl('register/username', self.form, _('Username already exists')) if self.email_already_exists(self.form['email'].value): return template.ltpl('register/username', self.form, _('Email already exists')) self._insert_user_to_db() add_default_lists(self.user_id) auth.login_user(session.get_session(), self.user_id) web.seeother(url='/register/after-signup', absolute=True) else: return template.ltpl('register/username', self.form, _('Please provide all information'))
def POST(self): form = self._email_form() if form.validates(): self.email = form['email'].value self.username = form['username'].value if self.username_already_exists(self.username): return template.ltpl('register/twitter/username', form, msg=_('Username already exists')) self._insert_user_to_db() auth.login_user(session.get_session(), self.user_id) web.seeother(url='/register/after-signup', absolute=True) else: return template.ltpl('register/twitter/username', form, msg=_('Please provide an username and email'))
def POST(self): form = self._email_form() if form.validates(): user_email = form['email'].value sess = session.get_session() user_id = sess['tw_user_id'] db = database.get_db() if user_id: db.update(tables='users', where='id=$user_id', vars={'user_id': user_id}, email=user_email) else: values = { 'name': sess['tw_name'], 'username': sess['tw_username'], 'twitter': sess['tw_twitter'], 'login_source': auth.LOGIN_SOURCE_TWITTER, 'email': user_email, } user_id = db.insert(tablename='users', **values) auth.login_user(session.get_session(), user_id) web.seeother(url='/register/after-signup', absolute=True) else: return template.ltpl('register/twitter/email', form, msg=_('Please provide an email'))
def GET(self): sess = session.get_session() if sess.get('user_id', False): return web.seeother(url='/', absolute=True) message = web.input(msg=None)['msg'] form = self.UsernameForm() return template.ltpl('recover_password/start', form, message)
def POST(self, user_id, token_id, token): user_id = int(user_id) token_id = int(token_id) form = self.PwdResetForm() if form.validates(): sess = session.get_session() if sess['pwdrecov_token_id'] != token_id or sess[ 'pwdrecov_user_id'] != user_id or sess[ 'pwdrecov_token'] != token: message = _( 'Sorry! We cannot verify that this user requested a password reset. Please try to reset your passord again.' ) return web.seeother( url='/recover_password?msg={}'.format(message), absolute=True) password = form.d.pwd1 auth.chage_user_password(user_id, password) db = database.get_db() db.update(tables='password_change_tokens', where='id=$id', vars={'id': token_id}, used=True, used_on=datetime.datetime.now()) auth.login_user(sess, user_id) self.send_email() return web.seeother('/recover_password_complete/') else: return template.ltpl('recover_password/change_pwd_form', form)
def template_for_showing_categories(self): subcategories = self.db.where( table='categories', parent=self.category['id'], order='is_default_sub_category desc, name') results = self.db.where(table='categories', parent=self.category.get('parent'), order='is_default_sub_category desc, name') siblings_categories = [] for row in results: if row.id != self.category['id']: siblings_categories.append(row) results = self.db.where(table='categories', id=self.category.get('parent')) for row in results: parent = row break else: parent = None data = {'csid_from_client': "", 'user_id': self.sess.user_id} boards = api_request("/api/profile/userinfo/boards", data=data).get("data", []) boards = [pin_utils.dotdict(board) for board in boards] return template.ltpl('category', self.category, cached_models.get_categories(), subcategories, boards, siblings_categories, parent)
def GET(self): sess = session.get_session() if self.username_already_exists(sess.fb_profile['username']): username = self.suggest_a_username(sess.fb_profile['username']) else: username = sess.fb_profile['username'] form = self.username_form() form['username'].set_value(username.lower()) form['email'].set_value(sess.fb_profile['email']) return template.ltpl('register/username', form)
def GET(self, name=None): sess = session.get_session() force_login(sess) logintoken = convert_to_logintoken(sess.user_id) profile_url = "/api/profile/userinfo/get" profile_owner_context = { "csid_from_client": "", "logintoken": logintoken } user = api_request(profile_url, data=profile_owner_context).get("data") user = dotdict(user) msg = web.input(msg=None)['msg'] return ltpl('editprofile', user, settings.COUNTRIES, name, msg)
def GET(self): sess = session.get_session() db = database.get_db() auth.force_login(sess) form = self.get_form() result_info = sess.get('result_info', []) results = db.where(table='pins', what='count(1) as pin_count', user_id=sess.user_id) for row in results: number_of_items_added = row.pin_count results = db.query(''' select parent.id, parent.name, child.id as child_id, child.name as child_name from categories parent left join categories child on parent.id = child.parent where parent.parent is null order by parent.position desc, parent.name, child.position desc, child.name ''') current_parent = None categories_as_list = [] for row in results: if not current_parent or current_parent['id'] != row.id: current_parent = { 'id': row.id, 'name': row.name, 'subcategories': [] } categories_as_list.append(current_parent) if row.child_id: current_parent['subcategories'].append({ 'id': row.child_id, 'name': row.child_name }) categories_columns = [[], [], [], []] categories_x_column = math.ceil(len(categories_as_list) / 4) count = 0 index = 0 for cat in categories_as_list: categories_columns[index].append(cat) count += 1 if count >= categories_x_column and index < 3: count = 0 index += 1 tagcloud = self.get_tag_cloud() return template.ltpl('pin_loader', form, result_info, categories_columns, number_of_items_added, sess.get('categories', []), tagcloud)
def GET(self): ''' Shows a form to introduce the data: username, email, password ''' sess = session.get_session() if 'nickname' in sess.profile and self.username_already_exists(sess.profile['nickname']): username = self.suggest_a_username(sess.profile['nickname']) elif 'nickname' in sess.profile: username = sess.profile['nickname'].lower() else: username = '' form = self.username_form() form['username'].set_value(username) if 'emails' in sess.profile and len(sess.profile['emails']) > 0: email_data = sess.profile['emails'][0] if 'value' in email_data: form['email'].set_value(email_data['value']) return template.ltpl('register/username', form)
def GET(self, user_id, token_id, token): user_id = int(user_id) token_id = int(token_id) db = database.get_db() results = db.where(table='password_change_tokens', id=token_id) for row in results: if (user_id == row.user_id and token == row.token and not row.used and datetime.datetime.now() < (row.created_on + datetime.timedelta(hours=row.valid_hours))): form = self.PwdResetForm() sess = session.get_session() sess['pwdrecov_user_id'] = user_id sess['pwdrecov_token_id'] = token_id sess['pwdrecov_token'] = token return template.ltpl('recover_password/change_pwd_form', form) message = _( 'Sorry! We cannot verify that this user requested a password reset. Please try to reset your passord again.' ) web.seeother(url='/recover_password?msg={}'.format(message), absolute=True)
def GET(self): sess = session.get_session() form = self._email_form() form['username'].set_value(sess.tw_username) return template.ltpl('register/twitter/username', form)
def GET(self): form = self._email_form() return template.ltpl('register/twitter/email', form)
def GET(self): return template.ltpl('recover_password/sent')