コード例 #1
0
ファイル: views.py プロジェクト: suprmim/lizaportal
    def get(self, *args, **kwargs):
        ## Check for auth:
        if not self.check_session():
            return ResponseRedirect(url_for('auth:login'))

        ## Allready validated:
        if self.request.user.validated:
            return ResponseRedirect(url_for('auth:validate'))

        ## Check for prev. token expired:
        if self.request.user.validation_code is not None and self.request.user.validation_code != '':
            expire, utoken = self.request.user.validation_code.split(' ')

            ## If prev. token not expired, got to validation page that show's error about prev. token not expired:
            if int(float(expire)) >= int(time.time()):
                return ResponseRedirect(url_for('auth:validate_confirm', token='tokennotexpired'))


        ## If auth is OK, user is not validated: resend confirmation letter:

        ## Generate new code:
        validation_code_a = self.generate_confirm_code()
        self.request.user.validation_code = " ".join(map(str, validation_code_a))
        db_session.add(self.request.user)
        db_session.commit()
  
        ## Send confirmation letter:
        self.send_confirmation(validation_code_a[1])

        return ResponseRedirect(url_for('auth:validate'))
コード例 #2
0
ファイル: views.py プロジェクト: suprmim/lizaportal
    def form_valid(self, form=None, **kwargs):

        ## Create session by self.request.user.id:
        self.authenticate()

        ## User authed but not validated, redirect to validation page:
        if not self.request.user.validated:
	    return ResponseRedirect(url_for('auth:validate'))

        return ResponseRedirect(url_for('index:index'))
コード例 #3
0
ファイル: views.py プロジェクト: suprmim/lizaportal
    def get(self, request, token=None, **kwargs):

        ## Check for auth:
        authed = self.check_session()

        ## If not authed, send to login page:
        if not authed:
            return ResponseRedirect(url_for('auth:login'))

        ## If authed, and allready validated:
        if self.request.user.validated:
            setattr(self, '__error', 'validated')
            return super(validateView, self).get(request, **kwargs)

        ## No validation code is database, show that account is not validated:
        if self.request.user.validation_code is None or self.request.user.validation_code == '':
            setattr(self, '__error', 'notvalidated')
            return super(validateView, self).get(request, **kwargs)

        ## If authed, but no token entered - show our validation form template:
        if token is None:
            return super(validateView, self).get(request, **kwargs)

        ## Tocken is not none, let's check it:
        expire, utoken = self.request.user.validation_code.split(' ')

        ## Tocken allready expired:
        if int(float(expire)) < int(time.time()):
            setattr(self, '__error', 'expired')
            return super(validateView, self).get(request, **kwargs)

        ## If we should show message that token is not expired allready, show it:
        elif token == 'tokennotexpired':
            setattr(self, '__error', 'notexpired')
            return super(validateView, self).get(request, **kwargs)


        ## Wrong token:
        if utoken != token:
            setattr(self, '__error', 'wrong')
            return super(validateView, self).get(request, **kwargs)

        ## Everything is OK, let's validate:
        self.request.user.validated = True
        db_session.add(self.request.user)
        db_session.commit()
        

        ## Go to auth page that will redirect to main:
        return ResponseRedirect(url_for('auth:login'))
コード例 #4
0
ファイル: views.py プロジェクト: suprmim/lizaportal
    def form_valid(self, form, **kwargs):

        ## Register user in Database:
        validation_code_a = self.generate_confirm_code()

        user = UsersModel(
            login=form.cleaned_data['username'], passwd=form.cleaned_data['passwd'], 
            email=form.cleaned_data['email'], validated=False, 
            fio=form.cleaned_data['fio'], disabled=False,
            phone=form.cleaned_data['phone'], 
            validation_code=" ".join(map(str, validation_code_a))
        )
        db_session.add(user)
        db_session.commit()

        ## AutoLogout:
        if self.check_session():
            Sessions().delete(self.request.user.id)

        self.request.user = user

        ## AutoLogin: Create session by self.request.user.id:
        self.authenticate()

        ## Send confirmation letter:
        self.send_confirmation(validation_code_a[1])

        return ResponseRedirect(url_for('auth:validate'))
コード例 #5
0
    def form_valid(self, form, *args, **kwargs):
        ##logging.error("DATA: %s" % form.cleaned_data)

        obj = Seminars()
        if self.__pk is not None:
            obj = db_session.query(Seminars).get(self.__pk)
            if obj is None:
                form.errors['pk'] = 'wrong_pk'
                return self.form_invalid(form)

        setattr(self, '__obj', obj)

        obj.disabled = False
        obj.owner_id = self.request.user.id

        obj.datebegin = form.cleaned_data['datebegin']
        obj.name = form.cleaned_data['name']
        obj.description = form.cleaned_data['description']
        obj.body = form.cleaned_data['body']
        obj.capacity = form.cleaned_data['capacity']
        obj.price = form.cleaned_data['price']

        db_session.add(obj)
        db_session.commit()

        return ResponseRedirect(url_for('seminars:crud_update', pk=obj.id))
コード例 #6
0
ファイル: authed.py プロジェクト: suprmim/lizaportal
    def prepare(self, *args, **kwargs):
        if not self.check_session():
            response = ResponseRedirect(url_for('auth:login'))
            return response.render(headers=self.get_headers())

        ## Check for access to default group:
        access_group = self.get_access_group()
        if access_group is not None and not self.check_access(access_group):

            ## Render template:
            body = render_template('403.tpl')

            ## Make flaskCBV Response() object:
            response = Response(body)

            ## Make Flask response object with status_code == 403:
            r = response.render(headers=self.get_headers())
            r.status_code = 403
            return r

        return super(AccessMixin, self).prepare(*args, **kwargs)
コード例 #7
0
    def get(self, request, pk, **kwargs):
        seminar = db_session.query(Seminars).get(pk)

        ## No such seminar:
        if seminar is None:
            return ResponseRedirect(url_for('seminars:list', pk=pk))

        ## Get seminar->user relation:
        su = db_session.query(SeminarUsers).filter(
            SeminarUsers.seminar_id == seminar.id)
        su = su.filter(SeminarUsers.user_id == self.request.user.id)

        ## Allready assigned:
        if self.assign and su.first() is not None:
            return ResponseRedirect(url_for('seminars:details', pk=pk))

        ## Allready not assigned:
        elif not self.assign and su.first() is None:
            return ResponseRedirect(url_for('seminars:details', pk=pk))

        ## Assign user to seminar:
        if self.assign:
            ## Too many listners:
            if not seminar.user_assigne_avalible:
                return ResponseRedirect(url_for('seminars:details', pk=pk))

            su = SeminarUsers()
            su.user_id = self.request.user.id
            su.seminar_id = seminar.id
            db_session.add(su)

        ## UnAssign user:
        else:
            su.delete()

        db_session.commit()

        return ResponseRedirect(url_for('seminars:details', pk=pk))
コード例 #8
0
ファイル: views.py プロジェクト: suprmim/lizaportal
 def get(self, *args, **kwargs):
     if self.check_session():
         return ResponseRedirect(url_for('index:index'))
     return super(registerView, self).get(*args, **kwargs)
コード例 #9
0
ファイル: views.py プロジェクト: suprmim/lizaportal
    def get(self, *args, **kwargs):
        if self.check_session():
            Sessions().delete(self.request.user.id)

        return ResponseRedirect(url_for('auth:login'))
コード例 #10
0
 def get(self, request, pk, **kwargs):
     obj = db_session.query(Seminars).filter(Seminars.id == pk)
     obj.delete()
     db_session.commit()
     return ResponseRedirect(url_for('seminars:crud_list'))
コード例 #11
0
ファイル: authed.py プロジェクト: suprmim/lizaportal
 def prepare(self, *args, **kwargs):
     if not self.check_session():
         response = ResponseRedirect(url_for('auth:login'))
         return response.render(headers=self.get_headers())
     return super(LoginRequiredMixin, self).prepare(*args, **kwargs)