Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

another simple user authentication system

  • Loading branch information...
commit 5e9b91c95405a83f2a3b0bde168a889695915a38 0 parents
Nestor G Pestelos Jr authored
2  .gitignore
@@ -0,0 +1,2 @@
+*.pyc
+*.swp
42 demo.py
@@ -0,0 +1,42 @@
+import web
+import hashlib
+import user
+
+# Go to http://localhost:5984/_utils to create the databases.
+# Change the names as needed.
+user_dbname = 'demo_user'
+
+urls = (
+ '/(.*)/', 'Redirect',
+ '/new', 'NewInstance',
+ '/admin', 'Admin',
+ '/', 'NewInstance'
+)
+
+app = web.application(urls, globals())
+
+render = web.template.render('static')
+
+class Admin:
+ def GET(self):
+ return "administration page"
+
+class NewInstance:
+ def GET(self):
+ return render.superuser()
+ def POST(self):
+ input = web.input()
+ user.create(user_dbname, 'root', \
+ hashlib.sha256(input.password1).hexdigest(), type='superuser')
+ raise web.seeother('/')
+
+class Redirect:
+ def GET(self, path):
+ web.seeother('/' + path)
+
+class Login:
+ def GET(self):
+ return render.login()
+
+if __name__ == '__main__':
+ app.run()
1  static/README.txt
@@ -0,0 +1 @@
+Please read http://webpy.org/cookbook/userauth.
10 static/blank.html.tmp
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title></title>
+ </head>
+ <body>
+ </body>
+</html>
11 static/login.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Login - Userauth Demo</title>
+ </head>
+ <body>
+ <p>Login</p>
+ </body>
+</html>
19 static/superuser.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Create Superuser - Userauth</title>
+ </head>
+ <body>
+ <form method="post" action="/new">
+ <p>
+ <label for="password1">Password:</label>
+ <input type="password" id="password1" name="password1" />
+ </p>
+ <p>
+ <input type="submit" value="Create Superuser" />
+ </p>
+ </form>
+ </body>
+</html>
7 user.py
@@ -0,0 +1,7 @@
+from couchdb import Server
+
+# Go to http://localhost:5984/_utils to create the database.
+
+def create(dbname, username, password, type='user'):
+ db = Server()[dbname]
+ db.create({'type': type, 'username': username, 'password': password})
Please sign in to comment.
Something went wrong with that request. Please try again.