Пример #1
0
 def identifyclient(self, conn):
     while self.running:
         try:
             req = conn.recv(1024)
             req = pickle.loads(req)
             print(req)
             if req[0] == 'Sign in':
                 ans = database.selectbyname(req[1], req[2])
                 print(ans)
                 if ans:
                     conn.send(pickle.dumps('okay'))
                     self.conns[req[1]] = conn
                     c = Thread(target=self.acceptmes, args=(conn, req[1]))
                     c.start()
                     break
                 else:
                     conn.send(pickle.dumps('Incorrect'))
             else:
                 if req[1] == "" and req[2] == "":
                     conn.send(pickle.dumps('Incorrect'))
                 else:
                     database.insertuser(req[1], req[2])
                     conn.send(pickle.dumps('okay'))
                     self.conns[req[1]] = conn
                     c = Thread(target=self.acceptmes, args=(conn, req[1]))
                     c.start()
                     break
         except:
             break
Пример #2
0
 def on_signup_clicked(self):
     username = self.username.text()
     pwd1 = self.pwd1.text()
     pwd2 = self.pwd2.text()
     if username and pwd1 and pwd2:
         if pwd1 != pwd2:
             reply = QMessageBox.critical(self, 'Message',
                                          '<font color="black">两次输入密码不一致!',
                                          QMessageBox.Ok, QMessageBox.Ok)
             return
         try:
             userinfo = []
             userinfo.append(str(username))
             userinfo.append(str(pwd1))
             database.insertuser(userinfo)
         except:
             reply = QMessageBox.critical(self, 'Message',
                                          '<font color="black">注册失败!',
                                          QMessageBox.Ok, QMessageBox.Ok)
             print("insert user catch exception")
             e = Exception(",...")
             raise e
             return
         else:
             reply = QMessageBox.information(self, 'Message',
                                             '<font color="black">注册成功!',
                                             QMessageBox.Ok, QMessageBox.Ok)
             # 跳转至登录界面
             from UI.loginMainWindow import loginMainWindow
             self.windowList = []
             FirstmainWindow = loginMainWindow()
             self.windowList.append(FirstmainWindow)
             self.close()
             if helper.modelversion == "light":
                 palette = QtGui.QPalette()
                 palette.setColor(FirstmainWindow.backgroundRole(),
                                  QtGui.QColor(255, 255, 255))
                 FirstmainWindow.setPalette(palette)
                 FirstmainWindow.setWindowTitle(
                     "Mine Information Management Platform")
                 FirstmainWindow.setFont(QtGui.QFont("Times New Roman", 12))
                 FirstmainWindow.show()
             else:
                 palette = QtGui.QPalette()
                 palette.setColor(FirstmainWindow.backgroundRole(),
                                  QtGui.QColor(68, 68, 68))
                 FirstmainWindow.setPalette(palette)
                 FirstmainWindow.setWindowTitle(
                     "Mine Information Management Platform")
                 styleFile = './UI/resource/qss/psblack.css'
                 Style = helper.Helper.readQss(styleFile)
                 FirstmainWindow.setStyleSheet(Style)
                 FirstmainWindow.show()
     else:
         reply = QMessageBox.critical(self, 'Message',
                                      '<font color="black">用户名或密码不能为空!',
                                      QMessageBox.Ok, QMessageBox.Ok)
Пример #3
0
 def adduser(self):
     password1 = self.passline1.text()
     password2 = self.passline2.text()
     if password1 == password2:
         login = self.logline.text()
         password = hashlib.md5(password1.encode('utf-8')).hexdigest()
         database.insertuser(login, password)
         self.refreshusers()
         self.passline1.setText('')
         self.passline2.setText('')
         self.logline.setText('')
         self.addstatus.setText("<font color='blue'>User added</font>")
     else:
         self.addstatus.setText("<font color='red'>Check password</font>")
Пример #4
0
def add_new_user():
    username = request.form["username"]
    password = request.form["password"]
    hash_value = generate_password_hash(password)
    teacher = 0
    
    #Check if username is already taken
    if database.checkusername(db, username) == False:
    	return render_template("new_user.html", error = True, errorcode = 1)
    	
    #Check if your new user is a teacher or not and puts user in database
    if "teacher" in request.form:
        teacher = 1    
    database.insertuser(db, username, hash_value, teacher)
    
    return redirect("/")
Пример #5
0
    def post(self):
        if self.checklogin():
            self.redirect('/')
        else:

            pagedict = {}
            pagedict['username'] = self.request.get('username')
            pagedict['password'] = self.request.get('password')
            pagedict['verify']   = self.request.get('verify')
            pagedict['email']    = self.request.get('email')
            pagedict['error']    = None

            if len(pagedict['username']) == 0 or len(pagedict['username']) > 20:
                pagedict['errusername'] = '******';pagedict['error']=True
            if database.fetchuser(pagedict['username']):
                pagedict['errusername'] = '******';pagedict['error']=True
            if len(pagedict['password']) < 8 or len(pagedict['password']) > 30:
                pagedict['errpassword'] = '******';pagedict['error']=True
            if pagedict['password'] != pagedict['verify']:
                pagedict['errverify'] = 'Passwords do not match';pagedict['error']=True
            matcher = re.compile(emailre)
            if pagedict['email'] and (matcher.match(pagedict['email']) is None or matcher.match(pagedict['email']).end() != len(pagedict['email'])):
                pagedict['erremail'] = 'Invalid email address';pagedict['error']=True

            if pagedict['error']:
                self.write_page(pagedict)
            else:
                secret = ''.join([random.choice(string.ascii_letters+string.digits) for n in range(32)])
                userInfo = {'username':pagedict['username'],
                            'password':hashlib.sha256((secret+pagedict['password']).encode('utf-8')).hexdigest(),
                            'email':pagedict['email'],
                            'secret':secret}
                
                if database.insertuser(userInfo):
                    self.login(userInfo['username'],userInfo['secret'])
                    self.redirect('/')
                else:
                    pagedict['errdb'] = 'database error'
                    self.write_page(pagedict)
Пример #6
0
def register_check():
    '''
	检查注册信息是否合法
	'''
    if request.method == 'POST':
        #获取网页端传输的信息
        a = request.get_data()
        data = json.loads(a)

        print("register check : ", data)

        if (data['p'] != data['c']):
            result = 'password and checkword are not equal!'
        else:
            #在数据库中新建用户
            result = database.insertuser(data['u'], data['p'])
        if result == 'OK':
            #向userinfo表添加新用户并为新用户创建文件夹
            database.insertuserinfo(data['u'])
            toolbar.makeuserdir(data['u'])
            return 'OK'
        else:
            return json.dumps(result)