Exemple #1
0
    def post(self):
        name = self.get_argument("name")
        oldp = self.get_argument("oldpwd", None)
        pwd = self.get_argument("pwd", None)
        pwd2 = self.get_argument("pwd2", None)
        user_dict = {"name": name}
        if oldp:
            user = Logic.user.get_user_by_id(self.uid)
            if encrypt_md5(oldp) == user.get("password"):
                if pwd and pwd2:
                    if pwd == pwd2:
                        user_dict.update(password=encrypt_md5(pwd))
                        r = {"status": True}
                    else:
                        r = {"status": False, "errmsg": "两次密码不一致"}
                else:
                    r = {"status": False, "errmsg": "请输入新密码"}
            else:
                r = {"status": False, "errmsg": "旧密码错误"}
        else:
            r = {"status": True}

        if r.get("status"):
            Logic.user.update(self.uid, user_dict)
        self.write(r)
Exemple #2
0
    def post(self):
        name = self.get_argument("name")
        oldp = self.get_argument("oldpwd", None)
        pwd = self.get_argument("pwd", None)
        pwd2 = self.get_argument("pwd2", None)
        user_dict = {"name":name}
        if oldp:
            user = Logic.user.get_user_by_id(self.uid)
            if encrypt_md5(oldp) == user.get("password"):
                if pwd and pwd2:
                    if pwd == pwd2:
                        user_dict.update(password = encrypt_md5(pwd))
                        r = {"status":True}
                    else:
                        r = {"status": False, "errmsg":"两次密码不一致"}
                else:
                    r = {"status":False, "errmsg":"请输入新密码"}
            else:
                r = {"status":False, "errmsg":"旧密码错误"}
        else:
            r = {"status":True}

        if r.get("status"):
            Logic.user.update(self.uid, user_dict)
        self.write(r)
Exemple #3
0
 def admin_login(self, username, password):
     admin = self.check_has_admin()
     if not (username and password):
         return self.error(u"请使用用户名密码登录")
     if username == admin.get('username') and \
        encrypt_md5(password) == admin.get('password'):
         return self.success(admin)
     else:
         return self.error(u"登录失败")
Exemple #4
0
 def admin_login(self, username, password):
     admin = self.check_has_admin()
     if not (username and password):
         return self.error(u"请使用用户名密码登录")
     if username == admin.get('username') and \
        encrypt_md5(password) == admin.get('password'):
         return self.success(admin)
     else:
         return self.error(u"登录失败")
Exemple #5
0
    def login(self, username, password):
        """"""
        with self._mc() as op:
            where = "`username`='{0}' and `password`='{1}'".format(
                username, encrypt_md5(password))

            result = op.select_one(where = where)

        if result:
            return self.success(result)
        return self.error(u"登录失败")
Exemple #6
0
    def login(self, username, password):
        """"""
        with self._mc() as op:
            where = "`username`='{0}' and `password`='{1}'".format(
                username, encrypt_md5(password))

            result = op.select_one(where=where)

        if result:
            return self.success(result)
        return self.error(u"登录失败")
Exemple #7
0
    def add_user(self, user_dict):
        user_dict['role'] = 1
        user_dict['password'] = encrypt_md5(user_dict.get("password"))
        username = user_dict.get("username")
        if self.check_exists_username(username):
            return self.error(u"用户名已存在")
        email = user_dict.get("email")
        if self.check_exists_email(email):
            return self.error(u"邮箱已注册")
        name = user_dict.get("name")
        if self.check_exists_name(name):
            return self.error(u"显示名已存在")

        fields, values = self.handle_insert(user_dict)
        with self._mc() as op:
            return self.success(op.insert(fields, values))
Exemple #8
0
    def add_user(self, user_dict):
        user_dict['role'] = 1
        user_dict['password'] = encrypt_md5(user_dict.get("password"))
        username = user_dict.get("username")
        if self.check_exists_username(username):
            return self.error(u"用户名已存在")
        email = user_dict.get("email")
        if self.check_exists_email(email):
            return self.error(u"邮箱已注册")
        name = user_dict.get("name")
        if self.check_exists_name(name):
            return self.error(u"显示名已存在")

        fields, values = self.handle_insert(user_dict)
        with self._mc() as op:
            return self.success(op.insert(fields, values))
Exemple #9
0
    def add_admin(self, user_dict):
        if self.check_has_admin():
            return self.error("管理员已存在")
        if not (user_dict.has_key('username') and user_dict.get('username')):
            return self.error("请提供管理员用户名")
        if not (user_dict.has_key('email') and user_dict.get('email')):
            return self.error("请提供管理员邮箱")
        if not (user_dict.has_key("password") and user_dict.get("password")):
            return self.error("请提供管理员密码")
        if not (user_dict.has_key("password2") and user_dict.get("password2")):
            return self.error("请提供重复密码")
        if user_dict["password"] != user_dict["password2"]:
            return self.error("两次输入密码不一致")
        pwd = user_dict.pop("password2")
        user_dict['password'] = encrypt_md5(pwd)
        user_dict['name'] = user_dict.get("username")
        with self._mc() as op:
            fields, values = self.handle_insert(user_dict)
            uid = op.insert(fields, values)

        return self.success(uid)
Exemple #10
0
    def add_admin(self, user_dict):
        if self.check_has_admin():
            return self.error("管理员已存在")
        if not (user_dict.has_key('username') and user_dict.get('username')):
            return self.error("请提供管理员用户名")
        if not (user_dict.has_key('email') and user_dict.get('email')):
            return self.error("请提供管理员邮箱")
        if not (user_dict.has_key("password") and user_dict.get("password")):
            return self.error("请提供管理员密码")
        if not (user_dict.has_key("password2") and user_dict.get("password2")):
            return self.error("请提供重复密码")
        if user_dict["password"] != user_dict["password2"]:
            return self.error("两次输入密码不一致")
        pwd = user_dict.pop("password2")
        user_dict['password'] = encrypt_md5(pwd)
        user_dict['name'] = user_dict.get("username")
        with self._mc() as op:
            fields, values = self.handle_insert(user_dict)
            uid = op.insert(fields, values)

        return self.success(uid)