Ejemplo n.º 1
0
    def delete_assignment(self, **data):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        #Report if not user who is logged in
        if DBSession.query(model.License).join(model.Assignment).filter(model.Assignment.id==data['id'], model.License.user_id==user_id).count() < 1:
            flash(('This incident has been reported'), 'error')
            redirect('/manage')

        locked = DBSession.query(model.Assignment.locked).filter(model.Assignment.id==data['id']).first().locked

        if locked == True:
            flash(_('Cannot delete. Assignment already redeemed.'), 'warning')
        else:
            license = DBSession.query(model.License).join(model.Assignment).filter(model.Assignment.id==data['id']).first()

            license.available = license.available + DBSession.query(model.Assignment).filter(model.Assignment.id==data['id']).first().count

            q = DBSession.query(model.Assignment).filter(model.Assignment.id==data['id']).delete()

            DBSession.flush()

            flash('Assignment deleted')

        redirect('/manage')
Ejemplo n.º 2
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Ejemplo n.º 3
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Ejemplo n.º 4
0
    def create_license(self, **data):

        user_name = request.identity['repoze.who.userid']
        user_id = DBSession.query(model.User.user_id).filter(model.User.user_name==user_name).first().user_id

        #Make sure that the computer_id belongs to user who is loggned in and that it has assignments
        if DBSession.query(model.Computer).filter(model.Computer.id==data['id'], model.Computer.user_id==user_id).count() < 1  or DBSession.query(model.Assignment).filter(model.Assignment.computer_id==data['id'], model.Assignment.user_id==user_id).count() < 1:
            flash(('This incident has been reported'), 'error')
            redirect('/manage')

        assignments = DBSession.query(model.Assignment.id).join(model.Computer).filter(model.Computer.id==data['id']).all()

        grouped_assignments = DBSession.query(func.sum(model.Assignment.count).label('count_sum'), model.Assignment, model.Computer, model.License).join(model.Computer).join(model.License).filter(model.Computer.id==data['id']).group_by(model.License.id).all()

        plain_license = LicenseFormat()

        for assignment in grouped_assignments:
            floating = 0
            if assignment.License.floating == True:
                floating = 1
            plain_license.add_plugin(assignment.License.plugin_id, assignment.License.l_type, assignment.count_sum, floating)

        plain_license.set_uuid1(grouped_assignments[0].Computer.uuid1)
        plain_license.set_uuid2(grouped_assignments[0].Computer.uuid2)

        plain_license.set_user_id(grouped_assignments[0].Computer.user_id)

        try:
            afx_ip = DBSession.query(model.Settings.afx_ip).first().afx_ip
            client = LicenseClient(afx_ip, 31568)
            license = client.get_license(plain_license.format_license())

            if license.find('Licensing Error') >= 0:
                flash(_("Licensing Error. Please email [email protected]"), 'warning')
                redirect('/manage')
            else:
                for assignment in assignments:
                    #Lock assignment
                    a = DBSession.query(model.Assignment).filter(model.Assignment.id==assignment.id).first()
                    a.locked = True
                    DBSession.flush()

                #Serve license file
                rh = response.headers
                rh['Content-Type'] = 'application/csv; charset=utf-8'
                disposition = 'attachment; filename="afx-license.dat"'
                rh['Content-disposition'] = disposition
                return license
        except:
            flash(_("Licensing Error. Please email [email protected]"), 'warning')
            redirect('/manage')
Ejemplo n.º 5
0
    def create_user(self, **kwargs):

        name = kwargs['name']
        email = kwargs['login_email'].lower()

        if DBSession.query(model.User).filter(model.User.user_name==email).count() > 0:
            flash(email + ' already exists!', 'error')
            kwargs['login_email']=''
            return self.admin_panel(**kwargs)
            #redirect('/admin_panel', kwargs)

        password = ''.join(random.choice(string.letters + string.digits + string.punctuation) for x in xrange(8))

        u = model.User()
        u.user_name = email
        u.display_name = name
        u.password = password

        licensing_portal_url = "licensing.authorityfx.com"

        subject = "New Authority FX Licensing Portal Account"
        body =    "Dear " + name + ",\n" \
                + "\n" \
                + "Please login into your new Authority FX licensing portal account with the following credentials: \n" \
                + "\n" \
                + licensing_portal_url + "\n" \
                + "\n" \
                + "username: "******"\n" \
                + "password: "******"\n" \
                + "\n" \
                + "We suggest that you change you password upon first login.\n" \
                + "\n" \
                + "Remember that all purchases are added into our licensing portal under the email address provided at checkout.  "\
                + "If you want to make puchases using another email address, please ensure that you change your login email via the " \
                + "settings page prior to making any new purchases.\n" \
                + "\n" \
                + "Thanks!"

        try:
            sender = SendMail()
            sender.send_mail(email, subject, body)
            DBSession.add(u)
            DBSession.flush()
            flash(email + ' added and notified via email.')
        except Exception, e:
            flash(('Could not send new login to ' + name + ", " + email + ": " + str(e)), 'error')
Ejemplo n.º 6
0
    def update_settings(self, **kwargs):

        fail = False
        changed = False
        update_password = False
        update_email = False
        msg = ''

        #Get user
        user_name = request.identity['repoze.who.userid']
        user = DBSession.query(model.User).filter(model.User.user_name==user_name).first()

        #Check if current password matches
        if user.validate_password(kwargs['current_password']) == False:
            fail = True
            msg = msg + "  Wrong password!"

        #Update name
        if fail != True and 'name' in kwargs:

            if len(kwargs['name']) > 0:

                #Hash new password
                user.display_name = kwargs['name']
                msg = msg + "  Successfully changed name."
                changed = True

        #Update email
        if fail != True and 'login_email' in kwargs:

            if len(kwargs['login_email']) > 0:

                new_email = kwargs['login_email'].lower()

                count = DBSession.query(model.User).filter(model.User.user_name==new_email).count()

                if count == 0:
                    user.user_name = new_email
                    msg = msg + '  Successfully changed login email.'
                    changed = True
                else:
                    fail = True
                    msg = msg + '  Email address already assigned.'


        #Update passwood
        if fail != True and 'new_password' in kwargs:

            if len(kwargs['new_password']) > 0:

                #Hash new password
                user._set_password(kwargs['new_password'])
                msg = msg + "  Successfully changed password."
                changed = True


        #if no errors write to database
        if fail != True and changed == True:
            DBSession.flush()
            flash(msg.strip())
            redirect('/logout_handler')
        elif fail != True and changed == False:
            flash('No Updates', 'warning')
            return dict(page='settings', form=SettingsForm, data=kwargs)
        else:
            flash(msg.strip(), 'error')
            return dict(page='settings', form=SettingsForm, data=kwargs)