Beispiel #1
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
Beispiel #2
0
def simple_login(validator, title='Login', username_label='User Name', 
    password_label='Password', parent=None, 
    error_message='Authentication Failed.', use_md5=True):
    tryagain = True
    while tryagain:
        uname = ''
        login_status = False
        #            
        d = gtk.Dialog(title, parent, gtk.DIALOG_MODAL,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
            gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        tbl = gtk.Table(2, 3)
        #
        ent_uname = gtk.Entry()
        lbl_uname = gtk.Label(username_label)
        lbl_uname.set_alignment(0, 0.5)
        tbl.attach(lbl_uname, 0, 1, 0, 1, xpadding=8, ypadding=8)
        tbl.attach(ent_uname, 1, 3, 0, 1, xpadding=8, ypadding=8)
        
        ent_passwd = gtk.Entry()
        ent_passwd.set_visibility(False)
        lbl_passwd = gtk.Label(password_label)
        lbl_passwd.set_alignment(0, 0.5)
        tbl.attach(lbl_passwd, 0, 1, 1, 2, xpadding=8, ypadding=8)
        tbl.attach(ent_passwd, 1, 3, 1, 2, xpadding=8, ypadding=8)
        
        vb = gtk.VBox()
        vb.pack_start(tbl, padding=10)
        
        d.vbox.pack_start(vb)
        d.vbox.show_all()
            
        ret = d.run()
            
        if ret == gtk.RESPONSE_ACCEPT:
            uname = ent_uname.get_text()
            passwd = ent_passwd.get_text()
            if use_md5:
                passwd2 = md5new(passwd).hexdigest()
            else:
                passwd2 = passwd
            
            if validator(uname, passwd2):
                login_status = True
                tryagain = False
            else:
                login_status = False
                tryagain = True
        else:
            login_status = False
            tryagain = False
        #
        d.destroy()
        if not login_status and tryagain:
            error(title='Error', message=error_message, parent=d)
        
    return (login_status, uname)
Beispiel #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
Beispiel #4
0
def simple_login(validator,
                 title='Login',
                 username_label='User Name',
                 password_label='Password',
                 parent=None,
                 error_message='Authentication Failed.',
                 use_md5=True):
    tryagain = True
    while tryagain:
        uname = ''
        login_status = False
        #
        d = gtk.Dialog(title, parent, gtk.DIALOG_MODAL,
                       (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK,
                        gtk.RESPONSE_ACCEPT))

        tbl = gtk.Table(2, 3)
        #
        ent_uname = gtk.Entry()
        lbl_uname = gtk.Label(username_label)
        lbl_uname.set_alignment(0, 0.5)
        tbl.attach(lbl_uname, 0, 1, 0, 1, xpadding=8, ypadding=8)
        tbl.attach(ent_uname, 1, 3, 0, 1, xpadding=8, ypadding=8)

        ent_passwd = gtk.Entry()
        ent_passwd.set_visibility(False)
        lbl_passwd = gtk.Label(password_label)
        lbl_passwd.set_alignment(0, 0.5)
        tbl.attach(lbl_passwd, 0, 1, 1, 2, xpadding=8, ypadding=8)
        tbl.attach(ent_passwd, 1, 3, 1, 2, xpadding=8, ypadding=8)

        vb = gtk.VBox()
        vb.pack_start(tbl, padding=10)

        d.vbox.pack_start(vb)
        d.vbox.show_all()

        ret = d.run()

        if ret == gtk.RESPONSE_ACCEPT:
            uname = ent_uname.get_text()
            passwd = ent_passwd.get_text()
            if use_md5:
                passwd2 = md5new(passwd).hexdigest()
            else:
                passwd2 = passwd

            if validator(uname, passwd2):
                login_status = True
                tryagain = False
            else:
                login_status = False
                tryagain = True
        else:
            login_status = False
            tryagain = False
        #
        d.destroy()
        if not login_status and tryagain:
            error(title='Error', message=error_message, parent=d)

    return (login_status, uname)
Beispiel #5
0
    def init_db_query(self):
        ret = []
        # groups
        query = """
        CREATE TABLE ms_groups(id integer primary key autoincrement,
        group_name text, resources text)
        """
        ret.append(query)
        #
        query = """
        INSERT INTO ms_groups(group_name, resources) 
            VALUES('ADMIN', '%s')
        """ % (
            self.resource_all_str
        )
        ret.append(query)
        #

        # users
        query = """
        CREATE TABLE ms_users(id integer primary key autoincrement,
        user_name text, real_name text, gid integer references 
        ms_groups(id), password text)
        """
        ret.append(query)
        #
        passwd = "admin"
        passwd_md5 = md5new(passwd).hexdigest()
        query = """
        INSERT INTO ms_users(user_name, real_name, gid, password) 
            VALUES('admin', 'Administrator', 1, '%s')
        """ % (
            passwd_md5
        )
        ret.append(query)
        #

        # categories
        query = """
        CREATE TABLE ms_categories(id integer primary key autoincrement,
        category_name text, note text)
        """
        ret.append(query)
        #

        # units
        query = """
        CREATE TABLE ms_units(id integer primary key autoincrement,
        unit_name text, note text)
        """
        ret.append(query)
        #

        # products
        query = """
        CREATE TABLE ms_products(id text primary key, 
        product_name text, price real, uid integer references ms_units(id),
        cid integer references ms_categories(id), stock integer, minstock integer)
        """
        ret.append(query)
        #

        # products flow
        query = """
        CREATE TABLE tr_flow(id integer primary key autoincrement, 
        dateinfo text, 
        user text,
        pid text references ms_products(id),
        flow_type text, amount integer, note text)
        """
        ret.append(query)
        #

        return ret
Beispiel #6
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()
Beispiel #7
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()
Beispiel #8
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()
Beispiel #9
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()
Beispiel #10
0
    def init_db_query(self):
        ret = []
        #groups
        query = '''
        CREATE TABLE ms_groups(id integer primary key autoincrement,
        group_name text, resources text)
        '''
        ret.append(query)
        #
        query = '''
        INSERT INTO ms_groups(group_name, resources) 
            VALUES('ADMIN', '%s')
        ''' % (self.resource_all_str)
        ret.append(query)
        #

        #users
        query = '''
        CREATE TABLE ms_users(id integer primary key autoincrement,
        user_name text, real_name text, gid integer references 
        ms_groups(id), password text)
        '''
        ret.append(query)
        #
        passwd = 'admin'
        passwd_md5 = md5new(passwd).hexdigest()
        query = '''
        INSERT INTO ms_users(user_name, real_name, gid, password) 
            VALUES('admin', 'Administrator', 1, '%s')
        ''' % (passwd_md5)
        ret.append(query)
        #

        #categories
        query = '''
        CREATE TABLE ms_categories(id integer primary key autoincrement,
        category_name text, note text)
        '''
        ret.append(query)
        #

        #units
        query = '''
        CREATE TABLE ms_units(id integer primary key autoincrement,
        unit_name text, note text)
        '''
        ret.append(query)
        #

        #products
        query = '''
        CREATE TABLE ms_products(id text primary key, 
        product_name text, price real, uid integer references ms_units(id),
        cid integer references ms_categories(id), stock integer, minstock integer)
        '''
        ret.append(query)
        #

        #products flow
        query = '''
        CREATE TABLE tr_flow(id integer primary key autoincrement, 
        dateinfo text, 
        user text,
        pid text references ms_products(id),
        flow_type text, amount integer, note text)
        '''
        ret.append(query)
        #

        return ret