Skip to content
Browse files

merge some .py to app.py, set default admin password, v0.4

  • Loading branch information...
1 parent 3e794fd commit 802de3f91768b67c820b3cd3c067007a5630bf01 @nopri committed Oct 15, 2012
Showing with 113 additions and 114 deletions.
  1. +5 −5 README.txt
  2. +87 −4 app.py
  3. +20 −4 config.ini.dist
  4. +1 −1 db.sql
  5. +0 −5 nop_browser.py
  6. +0 −75 nop_email.py
  7. +0 −20 nop_number.py
View
10 README.txt
@@ -29,13 +29,16 @@ Features:
Using:
- Python
- web.py
-- jQuery (bundled, old version)
+- jQuery/jQueryUI (bundled, old version)
- PyYAML
- BeautifulSoup
- GeoIP
- Python Imaging Library
- MySQL (and MySQLdb)
+
+Default user/password: admin
+
Installation (with Python already installed):
- We will use Apache HTTP Server for WSGI.
@@ -50,7 +53,7 @@ Installation (with Python already installed):
- Change into root directory of source code:
$ cd onlinestore-multi
-- Create new MySQL database, restore from dump file, set admin password:
+- Create new MySQL database and restore from dump file:
$ mysql -u root -p
mysql> create database onlinestore;
mysql> grant all privileges on onlinestore.* to onlinestore@localhost identified by 'onlinestore_password';
@@ -59,9 +62,6 @@ Installation (with Python already installed):
$ mysql -D onlinestore -u onlinestore -p < ./db.sql
- $ mysql -D onlinestore -u onlinestore -p
- mysql> update ms_user set password=md5('admin123') where id=1;
-
- In root directory of source code:
$ cp config.ini.dist config.ini
View
91 app.py
@@ -18,6 +18,7 @@
import urlparse
import random
import cStringIO
+import locale
#
try:
from hashlib import md5
@@ -32,9 +33,6 @@
import web
import yaml
from BeautifulSoup import BeautifulSoup
-from nop_number import number_format
-from nop_email import is_valid_email
-from nop_browser import detect_ua
import app_messages as m
import app_global_conf as gc
reload(m)
@@ -70,7 +68,7 @@ def cget(section, option, default='', strip=True):
############################### CONSTANT ###############################
-VERSION = '0.3'
+VERSION = '0.4'
NAME = 'Online Store'
PRECISION = 2
FORCE_PROMOTE = False
@@ -222,6 +220,91 @@ def cget(section, option, default='', strip=True):
############################### FUNCTION ###############################
+def is_valid_email(email):
+ tld = [
+ 'biz',
+ 'com',
+ 'info',
+ 'name',
+ 'net',
+ 'org',
+ 'pro',
+ 'aero',
+ 'asia',
+ 'cat',
+ 'coop',
+ 'edu',
+ 'gov',
+ 'int',
+ 'jobs',
+ 'mil',
+ 'mobi',
+ 'museum',
+ 'tel',
+ 'travel',
+ ]
+
+ user_allowed = '-_.%+'
+ host_allowed = '-_.'
+
+ #too short
+ if len(email) < 6:
+ return False
+ #
+
+ #split by @
+ try:
+ user, domain = email.rsplit('@', 1)
+ host, tl = domain.rsplit('.', 1)
+ except:
+ return False
+ #
+
+ #check for country code and toplevel
+ if len(tl) != 2 and tl not in tld:
+ return False
+ #
+
+ #remove char in user allowed
+ for i in user_allowed:
+ user = user.replace(i, '')
+ #
+ #remove char in host allowed
+ for i in host_allowed:
+ host = host.replace(i, '')
+ #
+
+ #should contain only alpha numeric
+ if user.isalnum() and host.isalnum():
+ return True
+ else:
+ return False
+
+
+def detect_ua(ua):
+ ret = {}
+ ret['mobile_document'] = ua
+ return ret
+
+
+def number_format(number, localeset='', places=0):
+ localeset = str(localeset)
+ saved = locale.getlocale(locale.LC_NUMERIC)
+ try:
+ locale.setlocale(locale.LC_NUMERIC, localeset)
+ except:
+ try:
+ localeset = localeset + '.utf8' #quick+dirty, will be fixed later
+ locale.setlocale(locale.LC_NUMBERIC, localeset)
+ except:
+ pass
+ if locale:
+ ret = locale.format('%.*f', (places, number), True)
+ locale.setlocale(locale.LC_NUMERIC, saved)
+ return ret
+ return number
+
+
def now(format='%Y-%m-%d %H:%M:%S'):
return time.strftime(format)
View
24 config.ini.dist
@@ -1,32 +1,48 @@
-[account]
-user =
-pass =
+#all account level will be enterprise in the future
+#please do not change the value
+#just ignore this section
+[account]
level = enterprise
+#MySQL database connection parameter
+#please replace the defaults with your configuration
[db]
host = localhost
user = onlinestore
pass =
name = onlinestore
+#SMTP setting, for sending email
+#smtp: host
+#user: smtp user
+#default: send as this user (shows in email)
[mail]
smtp =
user =
pass =
-default =
+default = info@
webmail =
+#Session
+#dir: session directory
[session]
dir = /tmp/onlinestore-multi-session/
+#Template
+#dir: template directory, please replace /path/to
[template]
dir = /path/to/onlinestore-multi/template/
+#URL
[url]
base = /
+#Font
+#dir: font directory, containing TTF font file(s)
[font]
dir = /usr/share/fonts/truetype/freefont/
+#doc
+#admin: admin documentation
[doc]
admin = /path/to/onlinestore-multi/README.txt
View
2 db.sql
@@ -381,7 +381,7 @@ CREATE TABLE `ms_user` (
LOCK TABLES `ms_user` WRITE;
/*!40000 ALTER TABLE `ms_user` DISABLE KEYS */;
-INSERT INTO `ms_user` VALUES (1,'admin',1,'',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL);
+INSERT INTO `ms_user` VALUES (1,'admin',1,'21232f297a57a5a743894a0e4a801fc3',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `ms_user` ENABLE KEYS */;
UNLOCK TABLES;
View
5 nop_browser.py
@@ -1,5 +0,0 @@
-
-def detect_ua(ua):
- ret = {}
- ret['mobile_document'] = ua
- return ret
View
75 nop_email.py
@@ -1,75 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-
-toplevels = [
-'biz',
-'com',
-'info',
-'name',
-'net',
-'org',
-'pro',
-'aero',
-'asia',
-'cat',
-'coop',
-'edu',
-'gov',
-'int',
-'jobs',
-'mil',
-'mobi',
-'museum',
-'tel',
-'travel',
-]
-
-user_allowed = '-_.%+'
-host_allowed = '-_.'
-
-def is_valid_email(email, tld=toplevels):
- #too short
- if len(email) < 6:
- return False
- #
-
- #split by @
- try:
- user, domain = email.rsplit('@', 1)
- host, tl = domain.rsplit('.', 1)
- except:
- return False
- #
-
- #check for country code and toplevel
- if len(tl) != 2 and tl not in tld:
- return False
- #
-
- #remove char in user allowed
- for i in user_allowed:
- user = user.replace(i, '')
- #
- #remove char in host allowed
- for i in host_allowed:
- host = host.replace(i, '')
- #
-
- #should contain only alpha numeric
- if user.isalnum() and host.isalnum():
- return True
- else:
- return False
-
-
-if __name__ == '__main__':
- try:
- email = sys.argv[1]
- except:
- email = ''
- #
- if not email:
- print 'usage: %s <email_address>' %(sys.argv[0])
- else:
- print is_valid_email(email)
View
20 nop_number.py
@@ -1,20 +0,0 @@
-import locale
-
-def number_format(number, localeset='', places=0):
- localeset = str(localeset)
- saved = locale.getlocale(locale.LC_NUMERIC)
- try:
- locale.setlocale(locale.LC_NUMERIC, localeset)
- except:
- try:
- localeset = localeset + '.utf8' #quick+dirty, will be fixed later
- locale.setlocale(locale.LC_NUMBERIC, localeset)
- except:
- pass
- if locale:
- ret = locale.format('%.*f', (places, number), True)
- locale.setlocale(locale.LC_NUMERIC, saved)
- return ret
- return number
-
-

0 comments on commit 802de3f

Please sign in to comment.
Something went wrong with that request. Please try again.