예제 #1
0
def loginfun(req):
   if req.method == 'POST':
      form = LoginForm(req.POST)
      if form.is_valid():
         idul = req.POST['idul']
         pasw = req.POST['pasw']
         user = authenticate(username=idul, password=pasw+idul)
         if user is not None:
            login(req, user)
            return HttpResponseRedirect('/home/')
         else:
            http = Http()
            http.get('https://capsuleweb.ulaval.ca/pls/etprod7/twbkwbis.P_WWWLogin')
            res = http.post('https://capsuleweb.ulaval.ca/pls/etprod7/twbkwbis.P_ValLogin', { 'sid': idul, 'PIN': pasw })
            c = re.compile('invalides', re.S)
            if not c.search(res):
               user = User.objects.create_user(idul, '', pasw+idul)
               user.is_active = False
               user.save()
               profile = user.get_profile()

               res = http.get('https://capsuleweb.ulaval.ca/pls/etprod7/bwskfshd.P_CrseSchd').decode('cp1252').encode('utf-8')
               c = re.compile('(<TABLE\s\sCLASS="datadisplaytable"(.*?)">.+?)<!--\s\s\*\* START', re.S)
               t = c.search(res).group(1)
               profile.horaire = t

               res = http.get('https://capsuleweb.ulaval.ca/pls/etprod7/bwskoacc.P_ViewAcctTotal').decode('cp1252').encode('utf-8')
               c = re.compile('<TABLE  CLASS="datadisplaytable"(.*?)">(.+?)<!--\s\s\*\* START', re.S)
               t = c.search(res).group(2)
               profile.compte = t

               res = http.post('https://capsuleweb.ulaval.ca/pls/etprod7/bwskgstu.P_StuInfo', { 'term_in': '201109' }).decode('cp1252').encode('utf-8')
               c = re.compile('<DIV class="pagetitlediv">(.+?)<!--\s\s\*\* START', re.S)
               t = c.search(res).group(1)
               profile.dossier = t

               profile.save()
               theuser = authenticate(username=idul, password=pasw+idul)
               login(req, theuser)
               return HttpResponseRedirect('/home/')
            else:
               return render_to_response('login.html', {'err':'Bad username/password'})
      else:
         return render_to_response('login.html', {'err':'Bad username/password'})

   res = render_to_response('login.html', {})
   res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
   res['Pragma'] = 'no-cache'
   return res
예제 #2
0
from Http import Http
from Settings import IDUL, PASW
import re

menu = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> \
        <link rel="stylesheet" media="screen" type="text/css" href="style.css" /> \
        Copyright <a href="http://agilbert.name/">Alain Gilbert</a> (<a href="http://twitter.com/#!/alain_gilbert">@alain_gilbert</a>) \
        <ul> \
        <li><a href="horaire.html">Horaire</a></li> \
        <li><a href="compte.html">Frais de scolarite</a></li> \
        <li><a href="dossier.html">Dossier scolaire</a></li> \
        </ul>'
http = Http()
http.get('https://capsuleweb.ulaval.ca/pls/etprod7/twbkwbis.P_WWWLogin')
http.post('https://capsuleweb.ulaval.ca/pls/etprod7/twbkwbis.P_ValLogin', { 'sid': IDUL, 'PIN': PASW })

with open('main.html', 'w+') as f:
   f.write(menu)

res = http.get('https://capsuleweb.ulaval.ca/css/Y_web_defaultapp.css')
with open('style.css', 'w+') as f:
   f.write(res)

res = http.get('https://capsuleweb.ulaval.ca/pls/etprod7/bwskfshd.P_CrseSchd')
with open('horaire.html', 'w+') as f:
   c = re.compile('(<TABLE\s\sCLASS="datadisplaytable"(.*?)">.+?)<!--\s\s\*\* START', re.S)
   t = c.search(res).group(1)
   f.write(menu)
   f.write(t)