Ejemplo n.º 1
0
 def post(self):
     weblog.info("%s.", self._request_summary())
     username = self.get_argument("username", None)
     passowrd = self.get_argument("passowrd", None)
     useremail = self.get_argument("useremail", None)
     userrole = self.get_argument("userrole")
     msg = []
     if username is None or username == "":
         msg.append(msg_define.USERNAME_IS_EMPTY)
     if passowrd is None or check_passord(passowrd) is None:
         msg.append(msg_define.USERPASSWORD_INVALID)
     if useremail is None or useremail == "":
         msg.append(msg_define.USEREMAIL_IS_EMPTY)
     elif check_email(useremail) is None:
         msg.append(msg_define.USEREMAIL_INVALID)
     if msg:
         return self.render('admin/useradd.html', message=msg)
     else:
         try:
             new_user = TblAccount()
             new_user.username = username
             new_user.password = passowrd
             new_user.email = useremail
             new_user.userrole = userrole
             new_user.userstate = msg_define.USER_NORMAL
             self.mysqldb().add(new_user)
             self.mysqldb().commit()
             return self.render('admin/usermanage.html',
                                users=get_user_list(self))
         except:
             weblog.exception("Add new user error!")
             self.mysqldb().rollback()
             return self.render('admin/useradd.html', message=msg)
Ejemplo n.º 2
0
def init_user():
    from database.tbl_account import TblAccount
    account = TblAccount()
    account.loginname = "youth303"
    account.nickname = u"青春"
    account.password = MD5("303303")
    account.email = ""
    account.userstate = 0
    account.userrole = 2
    db_session.add(account)
    db_session.commit()
    db_session.close()
Ejemplo n.º 3
0
def init_user():
    from database.tbl_account import TblAccount
    account = TblAccount()
    account.username = "******"
    account.password = MD5("111111")
    account.email = "*****@*****.**"
    account.userstate = 0
    account.userrole = 0
    db_session.add(account)
    db_session.commit()
    db_session.close()
Ejemplo n.º 4
0
def init_account():
    print('init one account...')
    from database.db_config import db_session
    from database.tbl_account import TblAccount
    from method.data_encode import MD5
    account = TblAccount()
    account.loginname = "Tornado"
    account.nickname = u"飞影"
    account.password = MD5("dgj_039103")
    account.userrole = 0
    account.userstate = 0
    account.email = "*****@*****.**"
    db_session.add(account)
    db_session.commit()
    db_session.close()
    print("add ok")
Ejemplo n.º 5
0
def init_account():
    print('init one account...')
    from database.db_config import db_session
    from database.tbl_account import TblAccount
    from method.data_encode import MD5
    account = TblAccount()
    account.username = "******"
    account.password = MD5("123456")
    account.userrole = 0
    account.email = "*****@*****.**"
    db_session.add(account)
    db_session.commit()
    db_session.close()
    print("add ok")
Ejemplo n.º 6
0
    def post(self):
        loginname = self.get_argument("loginname", None)
        nickname = self.get_argument('nickname', None)
        password = self.get_argument('password', None)
        email = self.get_argument("email", None)
        userrole = self.get_argument("userrole", "2")

        if loginname == "": loginname = None
        if nickname == "": nickname = None
        if password == "": password = None
        if email == "": email = None

        user = self.mysqldb().query(TblAccount).filter(TblAccount.loginname == loginname).first()
        if user is None:
            adduser = True
        else:
            adduser = False
        if loginname is not None and nickname is not None and password is not None and email is not None:

            password = MD5(password)
            if adduser:
                user = TblAccount()
            user.password = password
            user.loginname = loginname
            user.nickname = nickname
            user.email = email
            user.userrole = userrole
            user.userstate = 0
            if adduser:
                self.mysqldb().add(user)
            try:
                self.mysqldb().commit()
                return self.write(json_dumps({"error_code": 0, "msg": u"添加成功"}))
            except Exception as e:
                self.mysqldb().rollbakc()
                weblog.error("{}".format(e))
                return self.write(json_dumps({"error_code": 1, "msg": u"添加失败"}))
        else:
            return self.write(json_dumps({"error_code": 1, "msg": u"信息不完整"}))