def post(self, *args, **kwargs): question, answer, atype, products = self.getArgument_list( "question", "answer", "atype", "bind_products[]") if all((question, answer, atype, products)): try: curtime = datetime.now() curuser = self.user.get("id") ep_id = self.user.get("ep") product_question = ProductQuestion() product_question.question = question product_question.answer = answer product_question.atype = atype product_question.create_tm = curtime product_question.uid = curuser self.db.add(product_question) self.db.flush() for p in products: question_product_rel = ProductQuestionRel() question_product_rel.product_id = p question_product_rel.question_id = product_question.id question_product_rel.create_tm = curtime question_product_rel.uid = curuser question_product_rel.ep_id = ep_id self.db.add(question_product_rel) self.db.commit() return self.redirect(self.reverse_url("question_index")) except Exception as e: self.db.rollback() gen_log.error(e) flash(self, str(e)) else: flash(self, "parameters invalid") return self.redirect(self.reverse_url("question_create"))
def post(self): username, password = self.getArgument_list("username", "password") user = self.db.query(PlatUser).filter( PlatUser.email == username).first() if user is None: return self.redirect(self.reverse_url("login")) else: if user.checkPassword(password): self.Login(user.getAttributes()) else: flash(self, "密码错误") return self.redirect(self.reverse_url("login"))
def post(self, *args, **kwargs): phone, pwd = self.getArgument_list("phone", "pwd") if all((phone, pwd)): customer_user = self.db.query(Staff).filter( Staff.phone == phone).first() if customer_user and customer_user.checkPassword(pwd): self.Login(customer_user.getAttributes()) return self.redirect( self.reverse_url("customer_frontpage_dashboard")) else: flash(self, "phone number not exists or invalid password.") else: flash(self, "parameter invalid") return self.redirect(self.reverse_url("customer_frontpage_login"))
def get(self, *args, **kwargs): cid, = self.getArgument_list("cid") if cid: customer = self.db.query(Staff).filter(Staff.id == int(cid)).one() ep_rels_list = customer.ep_rel return self.render("customer_mgr/customer_detail.html", breadcrumb=[], customer=customer, products=MProduct.allEnabledProducts( self.db, self.user.get("ep")), ep_rels=json.dumps([ str(p.product_id) for p in ep_rels_list if p.product_id != 0 ])) else: flash(self, "cid not provide") return self.redirect(self.reverse_url("customer_index"))
def post(self): name, desc = self.getArgument_list("pname", "pdesc") if all((name, desc)): try: product = MProduct() product.name = name product.desc = desc product.add_user = self.user.get("id") product.add_time = datetime.now() product.label = generateUUID() product.ep_id = self.user.get("ep") self.db.add(product) self.db.commit() return self.redirect(self.reverse_url("product_index")) except Exception as e: self.db.rollback() gen_log.error(e) flash(self, str(e)) return self.redirect(self.reverse_url("product_create"))
def post(self, *args, **kwargs): ep, name, phone, pwd, status, products = \ self.getArgument_list("ep", "name", "phone", "pwd", "status", "bind_products[]") if all((ep, name, phone, pwd, status)): try: user = Staff() salt, password = user.genPassword(pwd) user.name = name user.phone = phone user.passwd = password user.salt = salt user.status = status user.create_tm = datetime.now() user.create_platuid = self.user.get("id") self.db.add(user) self.db.flush() user_enterprise_rel = StaffEnterpriseRel() user_enterprise_rel.ep_id = self.user.get("ep") user_enterprise_rel.cm_id = user.id user_enterprise_rel.product_id = 0 user_enterprise_rel.create_tm = datetime.now() user_enterprise_rel.create_method = USER_CREATE_METHOD_ENTERPRISE user_enterprise_rel.uid = self.user.get("id") self.db.add(user_enterprise_rel) for p in products: uer = StaffEnterpriseRel() uer.ep_id = user_enterprise_rel.ep_id uer.cm_id = user.id uer.product_id = p uer.create_tm = datetime.now() uer.create_method = user_enterprise_rel.create_method uer.uid = user_enterprise_rel.uid self.db.add(uer) self.db.commit() return self.redirect(self.reverse_url("customer_index")) except Exception as e: self.db.rollback() gen_log.error(e) flash(self, str(e)) else: flash(self, "parameter invalid") return self.redirect(self.reverse_url("customer_create"))
def post(self, *args, **kwargs): cid, = self.getArgument_list("cid") uid, name, phone, pwd, status, products = \ self.getArgument_list("uid", "name", "phone", "pwd", "status", "bind_products[]") ep_id = self.user.get("ep") cur_user_id = self.user.get("id") if all((uid, name, phone, status, products)): products = [int(p) for p in products] try: customer = self.db.query(Staff).filter(Staff.id == uid).one() customer.name = name customer.phone = phone if "" != pwd: salt, password = customer.genPassword(pwd) customer.salt = salt customer.passwd = password for cur_rel in customer.ep_rel: if cur_rel.product_id in products: products.remove(cur_rel.product_id) elif cur_rel.product_id != 0: customer.ep_rel.remove(cur_rel) self.db.delete(cur_rel) for p in products: uer = StaffEnterpriseRel() uer.ep_id = ep_id uer.cm_id = customer.id uer.product_id = p uer.create_tm = datetime.now() uer.create_method = USER_CREATE_METHOD_ENTERPRISE uer.uid = cur_user_id customer.ep_rel.append(uer) self.db.commit() return self.redirect(self.reverse_url("customer_index")) except Exception as e: self.db.rollback() gen_log.error(e) flash(self, str(e)) else: flash(self, "some parameters lost") return self.redirect(full_url(self, "customer_detail", {"cid": cid}))
def post(self, *args, **kwargs): username, gender, phone, code = self.getArgument_list( "username", "gender", "phone", "code") if all((username, gender, phone, code)): try: if self.db.query(~exists().where( Staff.phone == phone)).scalar(): customer = Staff() s, p = customer.genPassword(code) customer.name = username customer.phone = phone customer.passwd = p customer.salt = s customer.hashid = "" customer.gender = gender self.db.add(customer) self.db.flush() customer.hashid = hash_ids(customer.id) self.db.commit() return self.redirect( self.reverse_url("customer_frontpage_index")) else: flash(self, "手机号码已经被注册") except Exception as e: self.db.rollback() gen_log.error(str(e)) flash(self, str(e)) else: flash(self, "parameters invalid") return self.redirect(self.reverse_url("customer_frontpage_register"))
def post(self, *args, **kwargs): atitle, atag, adesc, pid = self.getArgument_list( "atitle", "atag", "adesc", "pid") if all((atitle, adesc, pid)): try: article = ProductArticle() article.title = atitle article.content = adesc article.create_tm = datetime.now() article.uid = self.user.get("id") article.p_id = pid article.ep_id = self.user.get("ep") self.db.add(article) self.db.flush() # 添加文章标签 tag_list = atag.split(" ") for tag in tag_list: tag = tag.strip() if tag != "": tag_item = ProductArticleTag() tag_item.tagname = tag tag_item.article_id = article.id tag_item.create_tm = datetime.now() tag_item.uid = self.user.get("id") self.db.add(tag_item) self.db.commit() return self.redirect( full_url(self, "product_article_index", {"pid": pid})) except Exception as e: self.db.rollback() gen_log.error(e) flash(self, str(e)) else: flash(self, "parameters invalid") return self.redirect( full_url(self, "product_article_create", {"pid": pid}))
def post(self): cur_pass, set_pass = self.getArgument_list("cur_password", "set_password") me = self.get_current_user() self_obj = self.db.query(PlatUser).filter( PlatUser.id == me.get('id')).one() if self_obj and self_obj.checkPassword(cur_pass): try: salt, new_pass = self_obj.genPassword(set_pass) self_obj.salt = salt self_obj.passwd = new_pass self.db.commit() flash(self, "修改密码成功", "info") return self.redirect(self.reverse_url("admin_index")) except Exception as e: tornado.log.gen_log.error(e) flash(self, "出现异常 " + str(e)) else: flash(self, "原密码错误") return self.render("profile/personsetting.html")