def change_password(db, arg): user = getUser(db, userId=arg["paras"].get("id")) if (not user): ERROR("user %s not exist" % (arg["paras"].get("id"))) return USER_NOT_EXIST return user.changePassword(b64_decode(arg["paras"].get('oldPassword')), b64_decode(arg["paras"].get('newPassword')))
def change_password(db, arg): paras = arg["paras"] user = getAccount(db, userId=paras["id"]) if (not user): ERROR("user %s not exist" % (paras["id"])) return USER_NOT_EXIST return user.changePassword(b64_decode(paras["oldPassword"]), b64_decode(paras["newPassword"]))
def add_user(db, arg): paras = arg["paras"] account = paras["account"] user = getAccount(db, userName=account) if (user): WARNING("user %s already exist" % account) return USER_ALREADY_EXIST user = Account(db) user.name = account user.password = b64_decode(paras["password"]) if (not user.name or not user.password): ERROR("not username or password specified") return NOT_ENOUGH_PARAS user.email = paras["email"] user.phone = paras["phoneNumber"] ret = user.add() return ret
def reset_password(db, arg): user = getUser(db, userId=arg["paras"].get("id")) if (not user): ERROR("user %s not exist" % (arg["paras"].get("id"))) return USER_NOT_EXIST return user.resetPassword(b64_decode(arg["paras"].get("password")))
def reset_password(db, arg): paras = arg["paras"] user = getAccount(db, userId=paras["id"]) if (not user): ERROR("user %s not exist" % (paras["id"])) return USER_NOT_EXIST return user.resetPassword(b64_decode(paras["password"]))
def web_login(db, env, arg): paras = arg["paras"] user = userService.getUserByName(db, paras.get("account")) if (not user): return buildRetObj(USER_NOT_EXIST, None) ret = user.auth(b64_decode(paras.get("password"))) if ret == 0: data = {"id": user.myId, "name": user.name, "role": user.role} sessionObj = newSession(db, data) data["session"] = sessionObj return buildRetObj(OCT_SUCCESS, data) else: return buildRetObj(USER_PASSWD_ERR)
def add_user(db, arg): user = getUser(db, userName=arg["paras"].get("account")) if (user): WARNING("user %s already exist" % arg["paras"].get("account")) return USER_ALREADY_EXIST user = Account(db) user.name = arg["paras"].get("account") user.password = b64_decode(arg["paras"].get("password")) if (not user.name or not user.password): ERROR("not username or password specified") return NOT_ENOUGH_PARAS user.ukey = arg["paras"].get("ukey") user.email = arg["paras"].get("email") or "" user.phone = arg["paras"].get("phoneNumber") or "" return user.add()