aboutsummaryrefslogtreecommitdiff
path: root/web/webqtl/management/createUserAccountPage.py
blob: f002c6ed8f88bef0fe41aafc33dcf12b8ce5715a (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# This program is available from Source Forge: at GeneNetwork Project
# (sourceforge.net/projects/genenetwork/).
#
# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
#
#
#
# This module is used by GeneNetwork project (www.genenetwork.org)
#
# Created by GeneNetwork Core Team 2010/08/10
#
# Last updated by GeneNetwork Core Team 2010/10/20

import os
import string

from htmlgen import HTMLgen2 as HT

from base.templatePage import templatePage
from base import webqtlConfig



#XZ, 02/06/2009: Xiaodong created this class
class createUserAccountPage(templatePage):

    def __init__(self, fd):

        templatePage.__init__(self, fd)

        if not self.openMysql():
            return


        ifVerified = fd.formdata.getvalue('ifVerified')

        if ifVerified != 'GN@UTHSC':
            heading = "Error page"
            detail = ["You are NoT verified as administrator."]
            self.error(heading=heading,detail=detail)
            return
        else:

            user_name = fd.formdata.getvalue('user_name')
            password = fd.formdata.getvalue('password')
            retype_password = fd.formdata.getvalue('retype_password')

            if user_name or password or retype_password:
                user_name = string.strip(user_name)
                password = string.strip(password)
                retype_password = string.strip(retype_password)

                #XZ, check if the input user name exists.

                if len(user_name) == 0:
                    heading = "Error page"
                    detail = ["The user name can NOT be empty."]
                    self.error(heading=heading,detail=detail)
                    return

                self.cursor.execute( 'select count(name) from User where name="%s"' % user_name )
                result = self.cursor.fetchone()
                if result:
                    row_count = result[0]
                    if row_count:
                        heading = "Error page"
                        detail = ["The user name %s already exists in database. Please make up another user name." % user_name]
                        self.error(heading=heading,detail=detail)
                        return
                else:
                    heading = "Error page"
                    detail = ["No sql result returned when check user name."]
                    self.error(heading=heading,detail=detail)
                    return

                # check password
                if len(password) == 0 or len(retype_password) == 0:
                    heading = "Error page"
                    detail = ["The password can NOT be empty."]
                    self.error(heading=heading,detail=detail)
                    return
 
                if password != retype_password:
                    heading = "Error page"
                    detail = ["The passwords you entered are NOT consistent. Please go back and try again."]
                    self.error(heading=heading,detail=detail)
                    return

                #XZ, create new account
                self.cursor.execute( "insert into User (name, password, createtime, privilege) values ('%s', SHA('%s'), Now(), 'user')" % (user_name, password) )


            #show user table.
            TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee')

            userHeading = HT.Paragraph('User Table', Class="title")

            self.cursor.execute( 'select id, name, privilege from User order by name' )

            result = self.cursor.fetchall()

            userInfo = HT.Blockquote( 'There are %d users.' % len(result) )

            userTable = HT.TableLite(border=0, cellpadding=0, cellspacing=0, Class="collap", width="100%")

            userHeaderRow = HT.TR()
            userHeaderRow.append(HT.TD("User Id", Class='fs14 fwb ffl b1 cw cbrb'))
            userHeaderRow.append(HT.TD("User name", Class='fs14 fwb ffl b1 cw cbrb'))
            userHeaderRow.append(HT.TD("User privilege", Class='fs14 fwb ffl b1 cw cbrb'))
            userTable.append(userHeaderRow)

            for one_row in result:
                User_Id, User_name, User_privilege = one_row
                userRow = HT.TR()
                userRow.append(HT.TD("%s" % User_Id, Class='fs12 fwn ffl b1 c222'))
                userRow.append(HT.TD("%s" % User_name, Class='fs12 fwn ffl b1 c222'))
                userRow.append(HT.TD("%s" % User_privilege, Class='fs12 fwn ffl b1 c222'))
                userTable.append(userRow)

            #add user form
            createUserAccountForm = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', name='createUserAccountForm', submit=HT.Input(type='hidden'))

            user_name = HT.Input(type='text' ,name='user_name',value='', size=20,maxlength=20)
            password = HT.Input(type='password' ,name='password',value='', size=20,maxlength=20)
            retype_password = HT.Input(type='password' ,name='retype_password',value='', size=20,maxlength=20)
            submit_button = HT.Input(type='Submit', value='Submit', Class="button")

            createUserAccountForm.append(
                HT.Blockquote( HT.Font('Create one new account:     User Name ', color='red'), user_name, HT.Font('   Password ', color='red'), password, HT.Font('   Retype Password ', color='red'), retype_password, submit_button ),
                HT.Input(type='hidden',name='FormID',value='createUserAccount'),
                HT.Input(type='hidden',name='ifVerified',value='GN@UTHSC')
            )

            """
            #manager form
            managerForm = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', name='managerForm', submit=HT.Input(type='hidden'))
            managerForm.append(
                HT.Input(type='Submit', value='Go to manager main page', Class="button"),
                HT.Input(type='hidden',name='FormID',value='managerMain'),
                HT.Input(type='hidden',name='ifVerified',value='GN@UTHSC')
            )
            """

            #TD_LR.append(managerForm, HT.BR(), userHeading, userInfo, HT.P(), createUserAccountForm, userTable, createUserAccountForm, HT.BR(), managerForm)
            TD_LR.append(userHeading, userInfo, HT.P(), createUserAccountForm, userTable, createUserAccountForm)

            self.dict['body'] =  str(TD_LR)
            self.dict['title'] = 'User account'