Пример #1
0
 def create(self):
     schema = StudentForm()
     try:
         form_result = schema.to_python(request.params)
     except formencode.validators.Invalid, error:
         c.form_result = error.value
         c.form_errors = error.error_dict or {}
         h.flash('Tao moi that bai', 'error')
         return render('/student/new.html')
Пример #2
0
    def active(self):
        token = request.params['token']
        student = Session.query(model.UsersInfo).filter_by(token=token).first()
        if student:
            student.active = 1
            Session.commit()
            h.flash('Tai khoan cua ban da active thanh cong. Moi ban dang nhap de tiep tuc su dung.', 'success')

        else:
            h.flash('Duong dan kich hoat chua chinh xac.', 'error')
        redirect(url(controller='account', action='signin'))
Пример #3
0
 def update(self, id):
     schema = StudentForm()
     student = Session.query(model.Users).filter(Users.id == id).first()
     c.id = int(id)
     if not student:
         abort(404, '404 Not Found')
     try:
         form_result = schema.to_python(request.params, c)
     except formencode.validators.Invalid, error:
         c.form_result = error.value
         c.form_errors = error.error_dict or {}
         h.flash('Cap nhat that bai', 'error')
         return render('/student/edit.html')
Пример #4
0
 def delete(self):
     student_id = request.params['student_id']
     student = Session.query(model.Users).filter_by(id=student_id).first()
     course_id = request.params['course_id']
     course = Session.query(model.Course).filter_by(id=course_id).first()
     register = Session.query(model.association_table).filter_by(
         user_id=student_id, course_id=course_id).first()
     if not register:
         abort(404, '404 Register Not Found')
     student.courses.remove(course)
     Session.commit()
     h.flash('Xoa dang ki thanh cong', 'success')
     return redirect(
         h.url(controller='students', action='show', id=student_id))
Пример #5
0
 def user_create(self):
     student = Session.query(model.Users).filter_by(
         email=request.environ['REMOTE_USER']).first()
     course_id = request.params['course_id']
     course = Session.query(model.Course).filter_by(id=course_id).first()
     register = Session.query(model.association_table).filter_by(
         user_id=student.id, course_id=course_id).first()
     if register:
         h.flash('Da dang ki tu truoc', 'error')
     else:
         student.courses.append(course)
         Session.commit()
         h.flash('Dang ki thanh cong', 'success')
     return redirect(
         url(controller='students', action='show', id=student.id))
Пример #6
0
 def signin(self):
     if not h.auth.authorized(h.auth.is_valid_user):
         if not request.params:
             return render('/derived/account/signin.html')
         schema = LoginForm()
         try:
             form_result = schema.to_python(request.params)
         except formencode.validators.Invalid, error:
             c.form_result = error.value
             c.form_errors = error.error_dict or {}
             h.flash('Dang nhap that bai', 'error')
             return render('/derived/account/signin.html')
         else:
             user = meta.Session.query(model.Users). \
                 filter_by(email=request.params['email'],
                           password=request.params['password']). \
                 first()
             if user:
                 if user.group_id == 1:
                     session['user'] = user
                     session.save()
                     if request.environ['HTTP_REFERER']:
                         print request.environ['HTTP_REFERER']
                         redirect(request.environ['HTTP_REFERER'])
                 else:
                     user_info = meta.Session.query(model.UsersInfo). \
                         filter_by(user_id=user.id). \
                         first()
                     if user_info.active == 1:
                         session['user'] = user
                         session.save()
                         if request.environ['HTTP_REFERER']:
                             print request.environ['HTTP_REFERER']
                             redirect(request.environ['HTTP_REFERER'])
                     else:
                         h.flash(
                             'Tai khoan cua ban chua duoc active, Vui long xac nhan bang dia chi email!',
                             'error')
                         return render('/derived/account/signin.html')
             else:
                 c.form_result = {
                     'email': request.params['email'],
                     'password': request.params['password']
                 }
                 c.form_errors = {
                     'email':
                     'Email va Password khong khop voi bat ki tai khoan nao'
                 }
                 if c.form_errors:
                     h.flash('Dang nhap that bai', 'error')
                 return render('/derived/account/signin.html')
Пример #7
0
                                'error')
                            return render('/derived/account/signin.html')
                else:
                    c.form_result = {
                        'email': request.params['email'],
                        'password': request.params['password']
                    }
                    c.form_errors = {
                        'email':
                        'Email va Password khong khop voi bat ki tai khoan nao'
                    }
                    if c.form_errors:
                        h.flash('Dang nhap that bai', 'error')
                    return render('/derived/account/signin.html')
        else:
            h.flash('Ban da dang nhap', 'success')
            return redirect(h.url(controller='account', action='signedin'))

    @authorize(ValidAuthKitUser())
    def signout(self):
        # The actual removal of the AuthKit cookie occurs when the response passes
        # through the AuthKit middleware, we simply need to display a page
        # confirming the user is signed out
        del session['user']
        return render('/derived/account/signedout.html')

    @authorize(ValidAuthKitUser())
    def signedin(self):
        # The actual removal of the AuthKit cookie occurs when the response passes
        # through the AuthKit middleware, we simply need to display a page
        # confirming the user is signed out
Пример #8
0
 def new(self, format='html'):
     if request.environ.has_key('REMOTE_USER') and \
                     'admin' not in request.environ['authkit.users'].user_group(request.environ['REMOTE_USER']):
         h.flash('Ban da dang nhap. Signout de tiep tuc', 'error')
         return redirect(h.url(controller='account', action='signedin'))
     return render('/student/new.html')
Пример #9
0
            c.user = model.Users(email=email, password=password)
            c.user.user_info = model.UsersInfo(name=name, token=token)
            Session.add(c.user)
            request.environ['authkit.users'].user_set_group(c.user.email, 'student')
            Session.commit()

            print 'commit xong'
            from rq import Queue
            from manager.queue.worker import conn
            email_content = render('/layout/email_layout/signup.html')
            print email_content
            q = Queue(connection=conn)
            print c.user.email
            q.enqueue(h.send_mail, 'Subject', email_content, c.user.email)

            h.flash('Successfully', 'success')
            return redirect(url(controller='students', action='notice'))

    def notice(self, format='html'):
        return render('/student/notice.html')

    def new(self, format='html'):
        if request.environ.has_key('REMOTE_USER') and \
                        'admin' not in request.environ['authkit.users'].user_group(request.environ['REMOTE_USER']):
            h.flash('Ban da dang nhap. Signout de tiep tuc', 'error')
            return redirect(h.url(controller='account', action='signedin'))
        return render('/student/new.html')

    def update(self, id):
        schema = StudentForm()
        student = Session.query(model.Users).filter(Users.id == id).first()