Exemple #1
0
    def get_all(self):
        try:

            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            cursor.callproc('getAllUsers')
            for result in cursor.stored_results():
                user = result.fetchall()
            users = []
            for x in user:
                u = User()
                u.id = x[0]
                u.password = x[1]
                u.last_login = x[2]
                u.is_superuser = x[3]
                u.username = x[4]
                u.first_name = x[5]
                u.last_name = x[6]
                u.email = x[7]
                u.is_staff = x[8]
                u.is_active = x[9]
                u.date_joined = x[10]
                users.append(u)
            conn.commit()
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)
        return users
Exemple #2
0
    def get_byusername(self, username):
        u = None
        try:

            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            args = [username]
            cursor.callproc('getUserByUserName', args)
            for result in cursor.stored_results():
                user = result.fetchall()

            for x in user:
                u = User()
                u.id = x[0]
                u.password = x[1]
                u.last_login = x[2]
                u.is_superuser = x[3]
                u.username = x[4]
                u.first_name = x[5]
                u.last_name = x[6]
                u.email = x[7]
                u.is_staff = x[8]
                u.is_active = x[9]
                u.date_joined = x[10]

            conn.commit()
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)
        return u
Exemple #3
0
    def get_byid(self, order_id):
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            order = None
            args = [order_id]

            cadao = CustomerAddressDao()
            pdao = PaymentInfoDao()
            # Calls the stored procedure
            cursor.callproc('getRetailOrderByOrderID', args)

            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for x in result.fetchall():
                    order = RetailOrder()
                    order.order_id = x[0]
                    order.date_ordered = x[1]
                    order.discount = x[2]
                    order.total_price = x[3]
                    order.status = x[4]

                    u = User()
                    u.id = x[5]
                    u.first_name = x[6]
                    u.last_name = x[7]
                    order.customer = u

                    p = PaymentInfo()
                    p.card_id = x[8]
                    p.last_four = x[9]
                    p.card_issuer = x[10]
                    order.card = p

                    a = CustomerAddress()
                    a.address_id = x[11]
                    a.street = x[12]
                    a.city = x[13]
                    a.state_code = x[14]
                    a.zip_code = x[15]
                    order.shipping_address = a

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return order
Exemple #4
0
    def post(self,request):
        user_id = request.session['user_id']
        username = request.session['username'] 
        info_form = CustomerInfoForm(request.POST)

        Cuserpass = ChangeUsernamePassword(request.POST)
        context = {}

        if 'edit-info' in request.POST:
            if info_form.is_valid():
                updateinfo = CustomerInfo()
                u = User()
                updateinfo.customer_id = user_id
                updateinfo.home_phone = info_form.cleaned_data['home_phone']
                updateinfo.work_phone = info_form.cleaned_data['work_phone']
                u.first_name = info_form.cleaned_data['first_name']
                u.last_name = info_form.cleaned_data['last_name']
                u.email = info_form.cleaned_data['email']
                updateinfo.set_user(u)
                self.cdao.update(updateinfo)

                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username']
            return redirect(reverse('customeraccount'))
  
        elif 'changeusernamepassword' in request.POST:
            if Cuserpass.is_valid():
                u = self.udao.get_byid(user_id)
                u.id = user_id
                u.username = Cuserpass.cleaned_data['username']
                current_password = Cuserpass.cleaned_data['password']
                if check_password(current_password, u.password):
                    x = Cuserpass.cleaned_data['password2']
                    u.password = make_password(x,salt=None,hasher='default')
                    self.udao.updateUserPass(u)

                    context['user_id'] = request.session['user_id'],
                    context['username'] = request.session['username'] 
                    return redirect(reverse('customeraccount'))
        elif 'deactivate' in request.POST:
            self.udao.deactivateUser(user_id)
            return redirect(reverse('login'))
        else:
            return redirect(reverse('customeraccount'))
Exemple #5
0
    def get_all(self):
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            cursor.callproc('getAllCustomerUserInfo')
            all_customer_info = []

            for result in cursor.stored_results():
                customers = result.fetchall()

            for x in customers:
                currentinfo = CustomerInfo()
                currentinfo.customer_id = x[0]
                currentinfo.work_phone = x[1]
                currentinfo.home_phone = x[2]
                u = User()
                u.id = x[3]
                u.password = x[4]
                u.last_login = x[5]
                u.is_superuser = x[6]
                u.username = x[7]
                u.first_name = x[8]
                u.last_name = x[9]
                u.email = x[10]
                u.is_staff = x[11]
                u.is_active = x[12]
                u.date_joined = x[13]
                currentinfo.set_user(u)
                all_customer_info.append(currentinfo)

                cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)
        return all_customer_info