Example #1
0
 def group_rename(self, widget):
     group = self.combo_grp.get_active_text()
     if group:
         newgroup = gtkutils.input(title='Rename Group', label='New group name',
         parent=self.group_edit_dialog, default=group).strip().upper()
         if newgroup:
             groups = self.get_groups()
             found=False
             for g in groups:
                 if newgroup == g[1] and newgroup!=group:
                     found=True
                     break
             #
             if found:
                 msg = 'Group %s already exists' %(newgroup)
                 gtkutils.error(title='Error', message=msg, 
                     parent=self.parent)
             else:
                 q = '''
                 update ms_groups set group_name=? where group_name=?
                 '''
                 a = (newgroup, group)
                 r = self.db.query(q, a, self.app.database)
                 if r[0] != 0:
                     msg = r[1]
                     dialog = gtkutils.error
                     dialog(title='Error', message=msg, parent=self.group_edit_dialog)
                 else:
                     self.group_populate_groups(combo=self.combo_grp, active=newgroup)
Example #2
0
 def group_new(self, widget):
     group = gtkutils.input(title='New Group', label='Group name',
         parent=self.group_edit_dialog).strip().upper()
     if group:
         groups = self.get_groups()
         found=self.get_group_id(group)
         #
         if found:
             msg = 'Group %s already exists' %(group)
             gtkutils.error(title='Error', message=msg, 
                 parent=self.parent)
         else:
             q = '''
             insert into ms_groups(group_name, resources)
             values(?,?)
             '''
             a = (group, '')
             r = self.db.query(q, a, self.app.database)
             if r[0] != 0:
                 msg = r[1]
                 dialog = gtkutils.error
                 dialog(title='Error', message=msg, parent=self.group_edit_dialog)
             else:
                 self.group_populate_groups(active=group, combo=self.combo_grp)
Example #3
0
 def passwd_change(self, widget):
     ret = False
     old = self.ent_old.get_text()
     old_md5 = md5new(old).hexdigest()
     new = self.ent_new.get_text()
     new_md5 = md5new(new).hexdigest()
     again = self.ent_again.get_text()
     again_md5 = md5new(again).hexdigest()
     
     if self.validate_login(self.myname, old_md5):
         #correct old password
         if new_md5 == again_md5:
             if new == '':
                 msg = 'New password could not be left blank'
                 gtkutils.error(title='Error', message=msg, parent=self.parent)
             else:
                 #change here
                 q = '''
                 update ms_users set password=? where id=?
                 '''
                 a = (new_md5, self.myuid)
                 r2 = self.db.query(q, a, self.app.database)
                 if r2[0] == 0:
                     #changed
                     msg = 'Password has been changed successfully'
                     gtkutils.info(title='Done', message=msg, parent=self.parent)
                     ret = True
                 else:
                     gtkutils.error(title='Error', message=r2[1], parent=self.parent)
         else:
             msg = 'New password mismatch'
             gtkutils.error(title='Error', message=msg, parent=self.parent)
     else:
         msg = 'Authentication failed'
         gtkutils.error(title='Error', message=msg, parent=self.parent)
     #
     if ret:
         self.reset_ui()
     #
     return ret
Example #4
0
    def user_edit(self, widget):
        selection = self.trview_main.get_selection()
        model, selected = selection.get_selected_rows()
        iters = [model.get_iter(path) for path in selected]
        if iters:
            iter = iters[0]
            id = int(model.get_value(iter, 0))
            user = self.get_user(id)
            #
            d = gtk.Dialog('Edit User', self.parent, gtk.DIALOG_MODAL,
                (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                    gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
            d.set_size_request(self.app.main_win_width - 100, -1)

            tbl_user = gtk.Table(4, 3)        
            #
            ent_uname = gtk.Entry()
            ent_uname.set_text(user[1])
            lbl_uname = gtk.Label('User Name')
            lbl_uname.set_alignment(0, 0.5)
            tbl_user.attach(lbl_uname, 0, 1, 0, 1, xpadding=8, ypadding=8)
            tbl_user.attach(ent_uname, 1, 3, 0, 1, xpadding=8, ypadding=8)
            #
            ent_rname = gtk.Entry()
            ent_rname.set_text(user[2])
            lbl_rname = gtk.Label('Real Name')
            lbl_rname.set_alignment(0, 0.5)
            tbl_user.attach(lbl_rname, 0, 1, 1, 2, xpadding=8, ypadding=8)
            tbl_user.attach(ent_rname, 1, 3, 1, 2, xpadding=8, ypadding=8)
            #
            ent_passwd = gtk.Entry()
            lbl_passwd = gtk.Label('Password (enter to change)')
            lbl_passwd.set_alignment(0, 0.5)
            tbl_user.attach(lbl_passwd, 0, 1, 2, 3, xpadding=8, ypadding=8)
            tbl_user.attach(ent_passwd, 1, 3, 2, 3, xpadding=8, ypadding=8)
            #
            combo_group = gtk.combo_box_new_text()
            group = self.get_group_name(user[3])
            self.group_populate_groups(combo=combo_group, active=group)
            lbl_group = gtk.Label('Group')
            lbl_group.set_alignment(0, 0.5)
            tbl_user.attach(lbl_group, 0, 1, 3, 4, xpadding=8, ypadding=8)
            tbl_user.attach(combo_group, 1, 3, 3, 4, xpadding=8, ypadding=8)
            #
            d.vbox.pack_start(tbl_user)
            d.vbox.show_all()
            #
            ret = d.run()
            d.hide()
            
            if ret == gtk.RESPONSE_ACCEPT:
                uname = ent_uname.get_text().strip()
                rname = ent_rname.get_text().strip()
                passwd = ent_passwd.get_text().strip()
                passwd_md5 = md5new(passwd).hexdigest()
                group = combo_group.get_active_text()
                gid = 0
                if group:
                    gid = self.get_group_id(group)
                
                if not uname:
                    msg = 'User Name could not be left blank'
                    gtkutils.error(parent=self.parent, message=msg, 
                        title='Error')
                else:
                    found = self.get_user_id(uname)
                    if found and uname != user[1]:
                        msg = 'User %s already exists' %(uname)
                        gtkutils.error(message=msg, parent=d, title='Error')
                    else:
                        if passwd:
                            q = '''
                            update ms_users set user_name=?, real_name=?, gid=?, password=? 
                            where id=?
                            '''
                            a = (uname, rname, gid, passwd_md5, id)
                        else:
                            q = '''
                            update ms_users set user_name=?, real_name=?, gid=?
                            where id=?
                            '''
                            a = (uname, rname, gid, id)
                        r = self.db.query(q, a, self.app.database)
                        if r[0] != 0:
                            msg = r[1]
                            dialog = gtkutils.error
                            dialog(title='Error', message=msg, parent=d)
                        #
                        self.draw_users()
            #
            #call external function when supplied
            #and when current user information is changed
            #act as bridge between status bar module
            #and user module
            if self.myuid == id:
                if self.external_func_user_edit:
                        self.external_func_user_edit(uname)
            d.destroy()
Example #5
0
    def user_new(self, widget):
        d = gtk.Dialog('New User', self.parent, gtk.DIALOG_MODAL,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        d.set_size_request(self.app.main_win_width - 100, -1)

        tbl_user = gtk.Table(4, 3)        
        #
        ent_uname = gtk.Entry()
        lbl_uname = gtk.Label('User Name')
        lbl_uname.set_alignment(0, 0.5)
        tbl_user.attach(lbl_uname, 0, 1, 0, 1, xpadding=8, ypadding=8)
        tbl_user.attach(ent_uname, 1, 3, 0, 1, xpadding=8, ypadding=8)
        #
        ent_rname = gtk.Entry()
        lbl_rname = gtk.Label('Real Name')
        lbl_rname.set_alignment(0, 0.5)
        tbl_user.attach(lbl_rname, 0, 1, 1, 2, xpadding=8, ypadding=8)
        tbl_user.attach(ent_rname, 1, 3, 1, 2, xpadding=8, ypadding=8)
        #
        ent_passwd = gtk.Entry()
        lbl_passwd = gtk.Label('Password')
        lbl_passwd.set_alignment(0, 0.5)
        tbl_user.attach(lbl_passwd, 0, 1, 2, 3, xpadding=8, ypadding=8)
        tbl_user.attach(ent_passwd, 1, 3, 2, 3, xpadding=8, ypadding=8)
        #
        combo_group = gtk.combo_box_new_text()
        self.group_populate_groups(combo=combo_group)
        lbl_group = gtk.Label('Group')
        lbl_group.set_alignment(0, 0.5)
        tbl_user.attach(lbl_group, 0, 1, 3, 4, xpadding=8, ypadding=8)
        tbl_user.attach(combo_group, 1, 3, 3, 4, xpadding=8, ypadding=8)
        #
        d.vbox.pack_start(tbl_user)
        d.vbox.show_all()
        #
        ret = d.run()
        d.hide()
        
        if ret == gtk.RESPONSE_ACCEPT:
            uname = ent_uname.get_text().strip()
            rname = ent_rname.get_text().strip()
            passwd = ent_passwd.get_text().strip()
            passwd_md5 = md5new(passwd).hexdigest()
            group = combo_group.get_active_text()
            gid = 0
            if group:
                gid = self.get_group_id(group)
            
            if not uname:
                msg = 'User Name could not be left blank'
                gtkutils.error(parent=self.parent, message=msg, 
                    title='Error')
            else:
                found = self.get_user_id(uname)
                if found:
                    msg = 'User %s already exists' %(uname)
                    gtkutils.error(message=msg, parent=d, title='Error')
                else:
                    q = '''
                    insert into ms_users(user_name, real_name, gid, password)
                    values(?,?,?,?)    
                    '''
                    a = (uname, rname, gid, passwd_md5)
                    r = self.db.query(q, a, self.app.database)
                    if r[0] != 0:
                        msg = r[1]
                        dialog = gtkutils.error
                        dialog(title='Error', message=msg, parent=d)
                    #
                    self.draw_users()
        #
        d.destroy()