def POST(self, name=None): """ Responsible for handing profile editing calls """ sess = session.get_session() force_login(sess) logintoken = convert_to_logintoken(sess.user_id) form = self._form() if not form.validates(): return 'you need to fill in everything' if logintoken: data = { "name": form.d.name, "about": form.d.about, "website": form.d.website, "country": form.d.country, "hometown": form.d.hometown, "city": form.d.city, "csid_from_client": 'None', "logintoken": logintoken } data = api_request("api/profile/userinfo/update", "POST", data) if data['status'] == 200: raise web.seeother('/profile') else: msg = data['error_code'] raise web.seeother('/profile?msg=%s' % msg) get_input = web.input(_method='get') if 'user_profile' in get_input: raise web.seeother('/%s?editprofile=1' % user.username)
def POST(self, name=None): """ Updates social media accounts. """ sess = session.get_session() force_login(sess) logintoken = convert_to_logintoken(sess.user_id) form = self._form() if not form.validates(): return 'bad input' if logintoken: data = { "logintoken": logintoken, "csid_from_client": "", "facebook": form.d.facebook, "linkedin": form.d.linkedin, "twitter": form.d.twitter, "gplus": form.d.gplus } data = api_request("api/profile/userinfo/update", data=data) if data['status'] == 200: raise web.seeother('/social-media') else: mgs = data['error_code'] raise web.seeother('/profile?msg=%s' % msg)
def ltpl(*params): sess = session.get_session() if auth.logged_in(sess): logintoken = convert_to_logintoken(sess.user_id) # Getting profile of a given user profile_url = "/api/profile/userinfo/info" profile_owner_context = { "csid_from_client": "1", "id": sess.user_id, "logintoken": logintoken} user = api_request(profile_url, data=profile_owner_context)\ .get("data", []) if len(user) == 0: return u"Profile was not found" user = pin_utils.dotdict(user) db = database.get_db() acti_needed = user.activation notif_count = db.select('notifs', what='count(*)', where='user_id = $id', vars={'id': sess.user_id}) # all_albums = list(db.select('albums', where="user_id=%s" % (sess.user_id), order='id')) all_albums = [] boards = list(db.where(table='boards', order='name', user_id=sess.user_id)) categories_to_select = list(cached_models.get_categories_with_children(db)) return tpl('layout', tpl(*params), cached_models.get_categories(), boards, all_albums, user, acti_needed, notif_count[0].count, csrf_token,categories_to_select ) return tpl('layout', tpl(*params), cached_models.get_categories())
def get_items(self): sess = session.get_session() start = web.input(start=False).start if start: offset = 1 self.sess['offset'] = 1 else: offset = self.sess.get('offset', 1) if offset == 0: return [] logintoken = convert_to_logintoken(self.sess.get('user_id')) data = { "csid_from_client": '', "logintoken": logintoken, "page": offset, "query_type": "range", "items_per_page": settings.PIN_COUNT } if self.category['id'] != 0: results = self.db.where(table='categories', parent=self.category['id']) data['category_id_list'] = [self.category['id']] for row in results: data['category_id_list'].append(str(row.id)) data = api_request("api/image/query/category", "POST", data) if data['status'] == 200: if offset >= data['data']['pages_count']: self.sess['offset'] = 0 data_for_image_query = { "csid_from_client": '', "logintoken": logintoken, "query_params": data['data']['image_id_list'] } data_from_image_query = api_request("api/image/query", "POST", data_for_image_query) if data_from_image_query['status'] == 200: set_of_seen_items = self.sess['seen_items'] items_without_duplicates = [] for item in data_from_image_query['data']['image_data_list']: itemid = item['id'] if itemid not in set_of_seen_items: set_of_seen_items.add(itemid) items_without_duplicates.append(item) return items_without_duplicates return []
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 POST(self, pin_id): input_values = web.input(category_check=[]) form_data = self.form(input_values) if form_data.validates(): if not form_data.d.link and not form_data.d.product_url: return "Invalid url for the product" if not form_data.d.board_id and not form_data.d.board_name: return "Invalid board" if form_data.d.board_id: board = form_data.d.board_id else: board = db.insert('boards', name=form_data.d.board_name) sess = session.get_session() logintoken = convert_to_logintoken(sess.user_id) data = { 'image_id': pin_id, "csid_from_client": '', "logintoken": logintoken } data = api_request("api/image/query/hashtags", "POST", data) hash_tag_remove_list = [] if data['status'] == 200: hash_tag_remove_list = data['data']['hashtag_list'] data = { 'image_id': pin_id, 'image_title': form_data.d.title, 'image_desc': form_data.d.description, 'link': form_data.d.link, 'price': form_data.d.price or None, 'product_url': form_data.d.product_url, 'price_range': form_data.d.price_range, 'board_id': board, 'hash_tag_remove_list': hash_tag_remove_list, 'hash_tag_add_list': form_data.d.tags.split(), "csid_from_client": '', "logintoken": logintoken } data = api_request("api/image/mp", "POST", data) if data['status'] == 200: return web.seeother(url='/p/{}'.format( data['data']['external_id']), absolute=True) return "Invalid data"
def POST(self, name=None): """ Handler for changing email or username """ sess = session.get_session() force_login(sess) logintoken = convert_to_logintoken(sess.user_id) form = self._form() if not form.validates(): return form.note email_available = self._is_available(uid=sess.user_id, field="email", value=form.d.email) if not email_available: msg = "Please try another email, this one is already occupied" return web.seeother('?msg=%s' % msg) username_available = self._is_available(uid=sess.user_id, field="username", value=form.d.username) if not username_available: msg = "Please try another username, this one is already occupied" return web.seeother('?msg=%s' % msg) if logintoken: data = { "username": form.d.username, "email": form.d.email, "csid_from_client": 'None', "logintoken": logintoken } data = api_request("api/profile/userinfo/update", "POST", data) if data['status'] == 200: raise web.seeother('') else: msg = data['error_code'] raise web.seeother('?msg=%s' % msg)
def POST(self, name=None): sess = session.get_session() force_login(sess) form = self._form() form.validates() # db.update('users', where='id = $id', vars={'id': sess.user_id}, **form.d) logintoken = convert_to_logintoken(sess.user_id) if logintoken: data = { "private": form.d.private, "logintoken": logintoken, "csid_from_client": "None" } data = api_request("api/profile/userinfo/set_privacy", "POST", data) if data['status'] == 200: raise web.seeother('/privacy') else: msg = data['error_code'] raise web.seeother('/privacy?msg=%s' % msg)
def POST(self, name=None): sess = session.get_session() force_login(sess) form = self._form() if not form.validates(): raise web.seeother('/password?msg=bad input') logintoken = convert_to_logintoken(sess.user_id) if logintoken: data = { "old_password": form.d.old, "new_password": form.d.pwd1, "new_password2": form.d.pwd2, "logintoken": logintoken } data = api_request("api/profile/pwd", "POST", data) if data['status'] == 200: raise web.seeother('/password') else: msg = data['error_code'] raise web.seeother('/password?msg=%s' % msg)