root/branch/bass_boy/umitWeb/views/main.py @ 843

Revision 843, 2.3 kB (checked in by bass_boy, 6 years ago)

one more update on umitweb interface

Line 
1#-*- coding: utf-8 -*-
2# Copyright (C) 2007 Adriano Monteiro Marques <py.adriano@gmail.com>
3#
4# Author: Rodolfo da Silva Carvalho <rodolfo.ueg@gmail.com>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20from os.path import join, abspath, dirname, exists, pardir
21from umitWeb.Http import HttpResponse, Http404, HttpResponseRedirect
22from umitWeb.WebLogger import getLogger
23from umitWeb.Auth import authenticate, ERROR
24from umitWeb.SecurityParser import Security
25import mimetypes
26
27logger = getLogger("main")
28
29@authenticate()
30def index(req):
31    response = HttpResponse()
32    response.loadTemplate("index.html")
33    return response
34
35def serve_media(req, path):
36    response = HttpResponse()
37   
38    filename = join(dirname(__file__), pardir, 'media', *(path.split("/")))
39   
40    if not exists(filename):
41        raise Http404
42   
43    response['Content-type'] = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
44    response.write(open(filename, 'r').read())
45    return response
46
47def login(req):
48    resp = HttpResponse()
49    if req.POST:
50        resp['Content-type'] = "text/plain"
51        user = Security.get_user(req.POST['login'], req.POST['password'])
52       
53        if req.GET.has_key("json"):
54            if user:
55                req.session['umit_user'] = user
56                resp.write('OK')
57            else:
58                resp.write('FAIL')
59            return resp
60        else:
61            if user:
62                req.session['umit_user'] = user
63                return HttpResponseRedirect("/")
64    else:
65        resp.loadTemplate("login.html")
66        return resp
67   
68def logout(req):
69    if req.session.has_key("umit_user"):
70        del req.session['umit_user']
71    return HttpResponseRedirect("/")
Note: See TracBrowser for help on using the browser.