def _PUT(self, *param, **params): user_id = param[0] if not validates_param_id(self, user_id): self.logger.debug("Failed to update account. the value of parameter is invalid.") return web.notfound(self.view.alert) if not validates_user(self): self.logger.debug("Failed to update account. the value of input is invalid.") return web.badrequest(self.view.alert) user = findby1(self.orm, user_id) if not user: self.logger.debug("Failed to update account. No such account - id=%s" % user_id) return web.notfound() cmp_user = findby1email(self.orm, self.input.email) if not cmp_user is None: if int(user_id) != cmp_user.id: self.logger.debug("Failed to update account. The same mail address '%s' already exist - user='******'" % (self.input.email, cmp_user.nickname)) return web.conflict(web.ctx.path) user.nickname = self.input.nickname user.email = self.input.email user.languages = self.input.languages if not is_empty(self.input.new_password): if compare_password(self, user) == False: return web.badrequest(self.view.alert) (password, salt) = sha1encrypt(self.input.new_password) user.password = password user.salt = salt update(self.orm, user) return web.seeother(web.ctx.path)
def _GET(self, *param, **params): user_id = param[0] if not validates_param_id(self, user_id): self.logger.debug("Failed to update account. the value of parameter is invalid.") return web.notfound(self.view.alert) user = findby1(self.orm, user_id) if not user: self.logger.debug("Failed to get account - id=%s" % user_id) return web.notfound() self.view.user = user if self.is_mode_input(): locales = DEFAULT_LANGS.keys() self.view.locales = locales return True
def _GET(self, *param, **params): user_id = param[0] if not validates_param_id(self, user_id): self.logger.debug( "Failed to update account. the value of parameter is invalid.") return web.notfound(self.view.alert) user = findby1(self.orm, user_id) if not user: self.logger.debug("Failed to get account - id=%s" % user_id) return web.notfound() self.view.user = user if self.is_mode_input(): locales = DEFAULT_LANGS.keys() self.view.locales = locales return True
def _DELETE(self, *param, **params): user_id = param[0] if not validates_param_id(self, user_id): self.logger.debug("Failed to delete account. the value of parameter is invalid.") return web.notfound(self.view.alert) user = findby1(self.orm, user_id) if not user: self.logger.debug("Failed to delete account. No such account - id=%s" % user_id) return web.notfound() users = findbyall(self.orm) if len(users) <= 1: self.view.alert = "In case that Karesansui has one account only, It does not allow to delete account." return web.badrequest(self.view.alert) delete(self.orm, user) return web.seeother("/%s.%s" % ("user", "part"))
def _DELETE(self, *param, **params): user_id = param[0] if not validates_param_id(self, user_id): self.logger.debug( "Failed to delete account. the value of parameter is invalid.") return web.notfound(self.view.alert) user = findby1(self.orm, user_id) if not user: self.logger.debug( "Failed to delete account. No such account - id=%s" % user_id) return web.notfound() users = findbyall(self.orm) if len(users) <= 1: self.view.alert = "In case that Karesansui has one account only, It does not allow to delete account." return web.badrequest(self.view.alert) delete(self.orm, user) return web.seeother("/%s.%s" % ("user", "part"))
def _PUT(self, *param, **params): user_id = param[0] if not validates_param_id(self, user_id): self.logger.debug( "Failed to update account. the value of parameter is invalid.") return web.notfound(self.view.alert) if not validates_user(self): self.logger.debug( "Failed to update account. the value of input is invalid.") return web.badrequest(self.view.alert) user = findby1(self.orm, user_id) if not user: self.logger.debug( "Failed to update account. No such account - id=%s" % user_id) return web.notfound() cmp_user = findby1email(self.orm, self.input.email) if not cmp_user is None: if int(user_id) != cmp_user.id: self.logger.debug( "Failed to update account. The same mail address '%s' already exist - user='******'" % (self.input.email, cmp_user.nickname)) return web.conflict(web.ctx.path) user.nickname = self.input.nickname user.email = self.input.email user.languages = self.input.languages if not is_empty(self.input.new_password): if compare_password(self, user) == False: return web.badrequest(self.view.alert) (password, salt) = sha1encrypt(self.input.new_password) user.password = password user.salt = salt update(self.orm, user) return web.seeother(web.ctx.path)
def _PUT(self, *param, **params): if not validates_me(self): return web.badrequest(self.view.alert) if self.me.id != int(self.input.id): self.logger.info("Update account is failed, " "posted ID parameter is different from me ID " "- posted ID %s, me ID %s" % (self.input.id, self.me.id)) return web.badrequest(_('ID is wrong. Your ID is not %s.') % self.input.id) me = findby1(self.orm, self.input.id) if not me: self.logger.debug("Update account is failed, " "Did not exist account - id=%s" % self.input.id) return web.notfound() cmp_user = findby1email(self.orm, self.input.email) if not cmp_user is None: if me.id != cmp_user.id: self.logger.info("Update account is failed, " "Already exists mail address " "- %s, %s" % (me, cmp_user)) return web.conflict(web.ctx.path) if self.input.password: if compare_password(self, self.me) is False: return web.badrequest(self.view.alert) (password, salt) = sha1encrypt(self.input.new_password) me.password = password me.salt = salt me.email = self.input.email me.languages = self.input.languages me.nickname = self.input.nickname dba_update(self.orm, me) self.me = me return web.seeother(web.ctx.path)