def userPost(self): h.logm("DBG",5,"ACTION "+ h.getcalled()); if request.method != 'POST': h.logm("ERR",5,"EXCEPTION, method is " + request.method); return self.jsonErrorResponse(500, "adm/user action does only allow POST request method"); h.logm("DBG",5,"request.POST body: " + request.body); userSchema = json.loads(request.body); user = User(userSchema); db = self._py_object.app_globals.db; if db.users.find_one({'name': user.name}): h.logm("INF",5,"user already exist: " + str(user.encode())); return self.jsonErrorResponse(405, "user already exist with this name: " + str(user.encode())); db = self._py_object.app_globals.db; if db.users.find_one({'email': user.email}): h.logm("INF",5,"user already exist: " + str(user.encode())); return self.jsonErrorResponse(405, "user already exist with this email: " + str(user.encode())); h.logm("INF",5,"trying to create user: "******"Cannot create user: "******"oid" : str(userid) }; return self.jsonResponse(responseDict);
def users(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'GET': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/users does only allow GET request method") db = self._py_object.app_globals.db users = db.users.find() responseArray = [] for user in users: responseArray.append(User(user).encode()) return self.jsonResponse(responseArray)
def userPost(self): h.logm("DBG", 5, "ACTION " + h.getcalled()) if request.method != 'POST': h.logm("ERR", 5, "EXCEPTION, method is " + request.method) return self.jsonErrorResponse( 500, "adm/user action does only allow POST request method") h.logm("DBG", 5, "request.POST body: " + request.body) userSchema = json.loads(request.body) user = User(userSchema) db = self._py_object.app_globals.db if db.users.find_one({'name': user.name}): h.logm("INF", 5, "user already exist: " + str(user.encode())) return self.jsonErrorResponse( 405, "user already exist with this name: " + str(user.encode())) db = self._py_object.app_globals.db if db.users.find_one({'email': user.email}): h.logm("INF", 5, "user already exist: " + str(user.encode())) return self.jsonErrorResponse( 405, "user already exist with this email: " + str(user.encode())) h.logm("INF", 5, "trying to create user: "******"Cannot create user: "******"oid": str(userid) } return self.jsonResponse(responseDict)
c.logged = True c.message = '' schema = SignupValidator() try: form_result = schema.to_python(request.params) h.logm("DBG", 5, "f r " + str(request.params)) except formencode.Invalid, error: h.logm("ERR", 5, "f r " + str(request.params)) c.message = h.literal(htmlfill.escapenl_formatter(error)) return render('/signup.mako') else: user = User(request.params) if db.users.find({'email': user.email}).count(): c.message = ("email " + request.params['email'] + " already exist") return render('/signup.mako') elif db.users.find({'name': user.name}).count(): c.message = ("name " + request.params['name'] + " already exist") return render('/signup.mako') else: h.logm("INF", 5, "user " + str(user)) encoded = user.encode() h.logm("INF", 5, "user encoded " + str(encoded)) db.users.save(user.encode())
c.message = ''; schema = SignupValidator(); try: form_result = schema.to_python(request.params); h.logm("DBG",5,"f r "+ str(request.params)); except formencode.Invalid, error: h.logm("ERR",5,"f r "+ str(request.params)); c.message = h.literal(htmlfill.escapenl_formatter(error)); return render('/signup.mako'); else: user = User(request.params); if db.users.find({'email': user.email}).count(): c.message = ("email " + request.params['email'] + " already exist"); return render('/signup.mako'); elif db.users.find({'name': user.name}).count(): c.message = ("name " + request.params['name'] + " already exist"); return render('/signup.mako'); else: h.logm("INF",5,"user "+ str(user)); encoded = user.encode(); h.logm("INF",5,"user encoded "+ str(encoded)); db.users.save(user.encode()); h.redirect(url(controller='home', action='index'));