Exemplo n.º 1
0
class loginForm(FlaskForm):
    regNo = StringField(messageText('VATNumberLabel'),
                        validators=[requiredValidator])
    email = StringField(messageText('emailLabel'),
                        validators=[requiredValidator, emailValidator])
    password = PasswordField(messageText('passwordLabel'),
                             validators=[requiredValidator])
Exemplo n.º 2
0
class groupForm(FlaskForm):
    name = StringField(messageText('groupLabel'), [requiredValidator])
    desc = TextAreaField(messageText('descLabel'), [requiredValidator])
    users = SelectMultipleField(messageText('usersLabel'),
                                validators=[],
                                choices=[],
                                widget=select2MultipleWidget())
Exemplo n.º 3
0
class registerForm(FlaskForm):
    regNo = StringField(messageText('VATNumberLabel'),
                        id='regNo',
                        validators=[requiredValidator])
    companyName = StringField(messageText('companyNameLabel'),
                              id='companyName',
                              validators=[requiredValidator])
    userName = StringField(messageText('usernameLabel'),
                           validators=[requiredValidator])
    email = StringField(messageText('emailLabel'),
                        validators=[requiredValidator, emailValidator])
    password = PasswordField(messageText('passwordLabel'),
                             validators=[requiredValidator])
Exemplo n.º 4
0
def loginView(lang='dk'):
    if not 'token' in session:
        g.lang = lang
        kwargs = {'formWidth':300,
                  'contentTitle':messageText('newPassword'),
                  'breadcrumbs': breadCrumbs('authBP.loginView')}

        form = loginForm()
        if form.validate_on_submit():
            regNo = form.regNo.data
            email = form.email.data
            password = form.password.data

            dataDict = {'regNo':regNo,
                        'email':email,
                        'password':password}

            req = authAPI('login', method='post', dataDict=dataDict)
            if 'success' in req:
                session['token'] = req['token']
                session['email'] = req['email']
                session['roles'] = req['roles']
                flashMessage('loginSuccess')
                return redirect(url_for('indexView', lang=lang))
            else:
                print req
                flashMessage('loginError')

        return render_template(lang+'/auth/loginForm.html', form=form, **kwargs)
    else:
        flashMessage('alreadyLoggedIn')
        return redirect(url_for('indexView', lang=lang))
Exemplo n.º 5
0
def userProfileView(lang='dk'):
    g.lang = lang
    kwargs = {
        'title': messageText('userProfileTitle'),
        'breadcrumbs': breadCrumbs('userBP.userProfileView')
    }

    return render_template(lang + '/user/userProfileView.html', **kwargs)
Exemplo n.º 6
0
def validateCVR(obj_response, cvr):
    try:
        companyName = cvrapi(cvr)['firmaNavn']
    except Exception as E:
        companyName = messageText('cvrCheckError')
    obj_response.attr('#companyName', 'readonly', False)
    obj_response.attr('#companyName', 'value', companyName)
    obj_response.attr('#companyName', 'readonly', True)
Exemplo n.º 7
0
def settingsView(lang=None):
    g.lang = lang
    kwargs = {
        'title': messageText('settingsTitle'),
        'formWidth': '350',
        'breadcrumbs': breadCrumbs('settingsBP.settingsView')
    }
    return render_template(lang + '/settings/settingsView.html', **kwargs)
Exemplo n.º 8
0
class companyForm(FlaskForm):
    VATNumber = StringField(messageText('VATNumberLabel'),
                            validators=[requiredValidator])
    companyName = StringField(messageText('companyNameLabel'),
                              validators=[requiredValidator])
    addr = StringField(messageText('addrLabel'))
    addr2 = StringField(messageText('addr2Label'))
    postcode = StringField(messageText('postcodeLabel'))
    city = StringField(messageText('cityLabel'))
    contactName = SelectField(messageText('usernameLabel'),
                              choices=[],
                              widget=select2Widget(),
                              validators=[requiredValidator])
    email = StringField(messageText('emailLabel'),
                        validators=[requiredValidator, emailValidator])
    phone = IntegerField(messageText('phoneLabel'))
Exemplo n.º 9
0
def companyView(lang=None):
    g.lang = lang
    form = companyForm()
    kwargs = {
        'title': messageText('companyTitle'),
        'formWidth': '350',
        'breadcrumbs': breadCrumbs('settingsBP.companyView')
    }
    return render_template(lang + '/settings/companyView.html',
                           form=form,
                           **kwargs)
Exemplo n.º 10
0
class userForm(FlaskForm):
    name = StringField(messageText('usernameLabel'),
                       validators=[requiredValidator])
    email = StringField(messageText('emailLabel'),
                        validators=[requiredValidator, emailValidator])
    phone = StringField(messageText('phoneLabel'))
    isAdmin = BooleanField(messageText('isAdminLabel'))
    isSuperuser = BooleanField(messageText('isSuLabel'))
    groups = SelectMultipleField(messageText('groupsLabel'),
                                 choices=[],
                                 widget=select2MultipleWidget())
Exemplo n.º 11
0
def setPasswordView(lang='dk', tok=None):
    g.lang = lang
    kwargs = {'formWidth':300,
              'contentTitle':str(tok),
              'title':messageText('setPasswordTitle'),
              'breadcrumbs': breadCrumbs('authBP.setPasswordView')}

    form = setPasswordForm()

    if form.validate_on_submit():
        req = authAPI('setPassword', method='post', dataDict=dataDict, token=session['token'])
        if r.status_code == 404:
            flashMessage('userDoesNotExist')
        elif 'success' in req:
            flashMessage('passwordSet')

    return render_template(lang+'/auth/setPasswordForm.html', form=form, **kwargs)
Exemplo n.º 12
0
def changePasswordView(lang='dk'):
    g.lang = lang
    kwargs = {
        'formWidth': 300,
        'contentTitle': messageText('changePassword'),
        'breadcrumbs': breadCrumbs('userBP.changePasswordView')
    }

    form = changePasswordForm()

    if form.validate_on_submit():

        dataDict = {'password': form.password.data}

        req = authAPI(endpoint='changePassword',
                      method='put',
                      dataDict=dataDict,
                      token=session['token'])
        flashMessage('passwordChanged')

    return render_template(lang + '/user/changePasswordForm.html',
                           form=form,
                           **kwargs)
Exemplo n.º 13
0
def userView(lang=None, id=None, function=None):
    # universal variables

    g.lang = lang
    form = userForm()
    kwargs = {
        'title': messageText('usersTitle'),
        'width': '',
        'formWidth': '400',
        'breadcrumbs': breadCrumbs('userBP.userView')
    }

    # Get users
    if function == None:
        users = getUsers()
        kwargs['tableColumns'] = columns(['userNameCol', 'emailCol'])
        kwargs['tableData'] = [[r['id'], r['name'], r['email']] for r in users]

        return render_template(lang + '/listView.html', **kwargs)
    elif function == 'delete':
        delUsr = deleteUser(id)

        if 'error' in delUsr:
            errorFlash(delUsr['error'])
        elif 'success' in delUsr:
            flashMessage('userDeleted')

        return redirect(url_for('userBP.userView', lang=lang))
    else:
        if function == 'update':
            # Get single user
            usr = getUser(id, includes=['includeRoles', 'includeGroups'])

            form = userForm(name=usr['name'],
                            email=usr['email'],
                            phone=usr['phone'],
                            groups=[str(r['id']) for r in usr['groups']])

            if 'roles' in usr:
                for r in usr['roles']:
                    if r['title'] == 'Administrator':
                        form.isAdmin.checked = True
                    if r['title'] == 'Superuser':
                        form.isSuperuser.checked = True
#
# Get all groups
            form.groups.choices = [(str(r['id']), r['name'])
                                   for r in getGroups()]

            if form.validate_on_submit():
                dataDict = {
                    'name': form.name.data,
                    'email': form.email.data,
                    'phone': form.phone.data
                }

                roles = []
                if form.isAdmin.data:
                    roles.append('Administrator')
                if form.isSuperuser.data:
                    roles.append('Superuser')
                dataDict['roles'] = roles
                dataDict['groups'] = form.groups.data
                updateUser = putUser(dataDict=dataDict, id=id)
                if 'error' in updateUser:
                    errorFlash(updateUser['error'])
                elif 'success' in updateUser:
                    flashMessage('userUpdated')

                return redirect(url_for('userBP.userView', lang=lang))

            return render_template(lang + '/user/userForm.html',
                                   form=form,
                                   **kwargs)
        elif function == 'new':
            form = userForm()
            groups = [(str(r['id']), r['name']) for r in getGroups()]
            form.groups.choices = groups

            if form.validate_on_submit():
                dataDict = {
                    'name': form.name.data,
                    'email': form.email.data,
                    'phone': form.phone.data
                }
                roles = []
                if form.isAdmin.data:
                    roles.append('Administrator')
                if form.isSuperuser.data:
                    roles.append('Superuser')
                dataDict['roles'] = roles
                dataDict['groups'] = form.groups.data
                newUser = postUser(dataDict)
                if 'error' in newUser:
                    if newUser['error'] == 'User already exist':
                        flashMessage('userExists')
                    else:
                        errorFlash(newUser['error'])
                elif 'success' in newUser:
                    flashMessage('userCreated')

                return redirect(url_for('userBP.userView', lang=lang))
            return render_template(lang + '/user/userForm.html',
                                   form=form,
                                   **kwargs)

    return render_template(lang + '/listView.html', **kwargs)
Exemplo n.º 14
0
def groupView(function=None, id=None, lang=None):
    # global variables
    g.lang = lang
    kwargs = {
        'title': messageText('userGrpTitle'),
        'width': '600',
        'formWidth': '350',
        'breadcrumbs': breadCrumbs('userBP.groupView')
    }

    if function == None:
        # perform API request
        req = getGroups(includes=['includeUsers'])

        # set data for listView
        kwargs['tableColumns'] = columns(['usrGroupCol', 'usersCol'])
        kwargs['tableData'] = [[r['id'], r['name'],
                                len(r['users'])] for r in req]

        # return view
        return render_template(lang + '/listView.html', **kwargs)
    elif function == 'delete':
        delGroup = deleteGroup(id)

        if 'error' in delGroup:
            if delGroup['error'] == 'Group has users':
                flashMessage('grpHasUsers')
            else:
                errorFlash(delGroup['error'])
        elif 'success' in delGroup:
            flashMessage('grpDeleted')

        return redirect(url_for('userBP.groupView', lang=lang))

    else:
        if function == 'update':
            # Get single group
            grp = getGroup(id, includes=['includeUsers'])
            form = groupForm(name=grp['name'],
                             desc=grp['desc'],
                             users=[str(r['id']) for r in grp['users']])
            form.users.choices = [(str(r['id']), r['email'])
                                  for r in getUsers()]
            if form.validate_on_submit():
                dataDict = {
                    'name': form.name.data,
                    'desc': form.desc.data,
                    'users': [int(r) for r in form.users.data]
                }
                updateGroup = putGroup(dataDict=dataDict, id=id)
                if 'error' in updateGroup:
                    if updateGroup['error'] == 'Group already exist':
                        flashMessage('grpUpdated')
                    else:
                        errorFlash(updateGroup['error'])
                elif 'success' in updateGroup:
                    flashMessage('grpNew')

                return redirect(url_for('userBP.groupView', lang=lang))

        elif function == 'new':
            form = groupForm()
            form.users.choices = [(str(r['id']), r['email'])
                                  for r in getUsers()]

            if form.validate_on_submit():
                dataDict = {
                    'name': form.name.data,
                    'desc': form.desc.data,
                    'users': [int(r) for r in form.users.data]
                }
                newGroup = postGroup(dataDict)

                if 'error' in newGroup:
                    if newGroup['error'] == 'Group already exist':
                        flashMessage('grpExists')
                    else:
                        errorFlash(newGroup['error'])
                elif 'success' in newGroup:
                    flashMessage('grpNew')

                return redirect(url_for('userBP.groupView', lang=lang))
        return render_template(lang + '/user/groupForm.html', form=form)
Exemplo n.º 15
0
class changePasswordForm(FlaskForm):
    password = PasswordField(messageText('passwordLabel'),
                             validators=[requiredValidator])