示例#1
0
    def signin(self):
        if not h.auth.authorized(h.auth.is_valid_user):
            print ("chua dang nhap")
            if request.params:
                print ("vao day khong nhi ")
                user = Session.query(model.Users). \
                    filter_by(email=request.params['email'],
                              password=request.params['password']). \
                    first()
                if user:
                    print ("dang nhap roi")
                    session['user'] = user
                    session.save()

                    print (user.email)
                    if (user.email == '*****@*****.**'):
                        return redirect(h.url('signedin'))
                        # return redirect(url(controller='courses', action='index'))
                    else:
                        if user.user_info.active == 1:
                            return redirect(url(controller='students', action='show', id=user.id))
                        else:
                            session.delete()
                            return render_jinja2('/layout/not_active.html')

                    print (user)

                else:
                    return render_jinja2('/account/singin.html')
            else:
                print ("vao 1")
                return render_jinja2('/account/singin.html')
        else:
            print ("vao 2")

            c.user_group = Session.query(Users).filter_by(email=request.environ['REMOTE_USER']).first()
            print ("AABBBB")
            print (c.user_group.email == '*****@*****.**')
            if (c.user_group.email == '*****@*****.**'):
                return redirect(h.url('signedin'))
                #return redirect(url(controller='courses', action='index'))
            else :
                if c.user_group.user_info.active == 1 :
                    return redirect(url(controller='students', action='show', id = c.user_group.id))
                else:
                    session.delete()
                    return render_jinja2('/layout/not_active.html')

            user_group = Session.query(Users).filter_by(email=request.environ['REMOTE_USER']).first()
            print ("AABBBB")
            print (user_group.email == '*****@*****.**')
            if (user_group.email == '*****@*****.**'):
                return redirect(h.url('signedin'))
                #return redirect(url(controller='courses', action='index'))
            else :
                return redirect(url(controller='students', action='show', id = user_group.id))
示例#2
0
 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']
     session.delete()
     return render_jinja2('/account/singout.html')
示例#3
0
    def create(self):

        name = request.params['name']
        email = request.params['email']
        password = request.params['password']
        text_confirm = name + email + password
        token = hashlib.md5(text_confirm).hexdigest()
        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()
        email_content = render_jinja2('layout/active_email.html')
        h.send_mail('ACTIVE ACCOUNT', email_content, c.user.email)
        return "OK"

        email = request.params['email']
        password = request.params['password']
        groupid = 2
        a = Users()
        a.email = email
        a.password = password
        a.group_id = groupid
        Session.add(a)
        Session.commit()
        return "OK"
 def signin(self):
     if not h.auth.authorized(h.auth.is_valid_user):
         print("chua dang nhap")
         if request.params:
             print("vao day khong nhi ")
             user = Session.query(model.Users). \
                 filter_by(email=request.params['email'],
                           password=request.params['password']). \
                 first()
             if user:
                 print("dang nhap roi")
                 session['user'] = user
                 session.save()
                 print(user)
             else:
                 return render_jinja2('/account/singin.html')
         else:
             print("vao 1")
             return render_jinja2('/account/singin.html')
     else:
         print("vao 2")
         return redirect(h.url('signedin'))
示例#5
0
    def edit(self, id=None):
        if id is None:
            abort(404)
        student_q = Session.query(Users)
        student = student_q.filter_by(id=id).first()
        if student is None:
            abort(404)
        values = {
            'name': student.name,
            'password': student.password,
            'email': student.email
        }

        return htmlfill.render(render_jinja2('/students/edit.html'), values)
 def show(self, id, format='html'):
     c.student = Session.query(Users).filter_by(id=id).first()
     if not c.student:
         abort(404, '404 Not Found')
     c.student_courses = Session.query(association_table).filter_by(
         user_id=c.student.id).all()
     print(c.student_courses)
     print(len(c.student_courses))
     course = Course()
     c.array1 = []
     for item in c.student_courses:
         c.array1.append(
             Session.query(Course).filter_by(id=item.course_id).all())
     print("AAAAAAA")
     print(c.array1)
     #for course in c.array1:
     #   print (course.id)
     return render_jinja2('/students/show_item.html')
示例#7
0
    def showlist(self):
        c.title = 'Show Student'

        c.studentall = Session.query(Users).all()

        return render_jinja2('/students/list.html')
示例#8
0
 def new(self):
     return render_jinja2('/students/new.html')
示例#9
0
 def index(self):
     # Return a rendered template
     # return render('/students.mako')
     # or, return a string
     return render_jinja2('/layout/index.html')
示例#10
0
 def showlist_item(self):
     student = Session.query(Users).filter_by(
         email=request.environ['REMOTE_USER']).first()
     c.student_courses = Session.query(association_table).filter(
         user_id=student.id).all()
     return render_jinja2('/students/show_item.html')
示例#11
0
    def showlist(self):
        c.title = 'Show Courses'

        c.studentall = Session.query(Course).all()

        return render_jinja2('/course/list.html')
示例#12
0
 def new(self):
     return render_jinja2('/course/addcourse.html')
示例#13
0
 def index(self):
     # Return a rendered template
     #return render('/courses.mako')
     # or, return a string
     #return render_jinja2('/course/index.html')
     return render_jinja2('/layout/admin.html')