Ejemplo n.º 1
0
 def _create_user(self):
     if User1.by_name(self.get_argument('name', '')):
         raise AuthError("name is registered")
     if self.get_argument('password1', '') != self.get_argument('password2', ''):
         raise AuthError("Password error")
     user = User1()
     user.username = self.get_argument('name', '')
     user.password = self.get_argument('password1', '')
     self.db.add(user)
     self.db.commit()
Ejemplo n.º 2
0
 def get_current_user(self):
     username = self.session.get("user_name")
     if username:
         user = User1.by_name(username)
         if user:
             return user
         else:
             return Employee.by_name(username)
     else:
         return None
Ejemplo n.º 3
0
 def post(self):
     user = User1.by_uuid(self.get_argument('uuid', ''))
     delete = self.get_argument('delete', '')
     if delete == 'delete':
         self.db.delete(user)
         self.db.commit()
         self.redirect('/')
     elif user:
         user.username = self.get_argument('username', '')
         self.db.add(user)
         self.db.commit()
         self.redirect('/')
     else:
         self.write('error no')
Ejemplo n.º 4
0
 def post(self):
     user = User1.by_name(self.get_argument('name', ''))
     password = self.get_argument("password", "")
     if not user.locked:
         if user and user.auth_password(password):
             self.success_login(user)
             if user.loginnum == 1:
                 self.write('newuser.html')
             else:
                 self.redirect(self.get_argument("aaa", "/"))
         else:
             self.write("登录失败")
     else:
         self.write("此用户已经被锁定,请联系管理员")
Ejemplo n.º 5
0
    def get(self):
        #为用户添加头像
        # user = self.db.query(User1).filter(User1.id==1).first()
        # user.avatar = open("static/images/avatar11.jpg", "rb").read()
        # self.db.add(user)
        # self.db.commit()
        # user = self.db.query(User1).filter(User1.id == 2).first()
        # user.avatar = open("static/images/headpictrue.jpg", "rb").read()
        # self.db.add(user)
        # self.db.commit()
        user = self.db.query(User1).filter(User1.id == 2).first()

        user.avatar = open("static/images/headpictrue.jpg", "rb").read()

        self.db.add(user)
        self.db.commit()
        print '-' * 80
        users = User1.all()
        self.render(u"13_sqlalchemy_test.html",
                    currentuser=self.current_user,
                    users=users)
Ejemplo n.º 6
0
 def get(self):
     user = User1.by_uuid(self.get_argument('uuid', ''))
     self.db.delete(user)
     self.db.commit()
     self.redirect('/')
Ejemplo n.º 7
0
 def get_current_user(self):
     if self.session.get("user_name"):
         return User1.by_name(self.session.get("user_name"))
     else:
         return None