Permalink
Browse files

smaller changes

  • Loading branch information...
1 parent 82fb9ca commit 621da54c6f4343073bbfbb1fc8c5d14317c9bb34 oau committed Oct 17, 2012
Showing with 24 additions and 54 deletions.
  1. +3 −42 core.py
  2. +6 −0 smskrupp
  3. +3 −1 sql/smskrupp.sql
  4. +3 −2 templates/group.html
  5. +1 −1 templates/settings.html
  6. +8 −8 web.py
View
45 core.py
@@ -114,45 +114,6 @@ def get_group_admins(self, group_id):
'where groupId=? and admin=1', (group_id,))
return [{'id':row[0],'number':row[1],'alias':row[2]} for row in c]
- """
- def get_admin(self, src, dest, msg):
- ''' return pair (cmd, groupId)
- '''
- if not msg.startswith(config.admin_prefix):
- # not an admin command
- return None
- msg = msg[len(config.admin_prefix):]
-
- c = self.cursor
- c.execute('select a.keyword,m.groupId from qq_groupMembers m '+
- 'join qq_adminmap a on m.id = a.memberId '+
- 'where m.number=? and a.dest=? order by length(keyword) desc',
- (src,dest))
- for row in c:
- keyword = row[0]
- if len(keyword) > 0: keyword += ' '
- if msg.lower().startswith(keyword.lower()):
- msg_out = msg[len(keyword):]
- return keyword,msg_out,row[1]
- return None
-
- def get_sendout(self, src, dest, msg):
- ''' return pair (msg, groupId)
- '''
- c = self.cursor
- c.execute('select a.keyword,m.groupId from qq_groupMembers m '+
- 'join qq_sendmap a on m.id = a.memberId '+
- 'where m.number=? and a.dest=? order by length(keyword) desc',
- (src,dest))
- for row in c:
- keyword = row[0]
- if len(keyword) > 0: keyword += ' '
- if msg.lower().startswith(keyword.lower()):
- msg_out = msg[len(keyword):]
- return msg_out,row[1]
- return None
- """
-
def get_group_members(self, group_id):
''' return array of dicts describing members (id, number, alias, sender, admin)
'''
@@ -356,10 +317,10 @@ def get_webusers(self):
def get_webuser_groups(self, webuser_id):
c = self.cursor
- c.execute('select groupId,name from qq_webUserGroups wg '
+ c.execute('select groupId,name,keyword from qq_webUserGroups wg '
+'left join qq_groups g on g.id=wg.groupId where userId=?',
(webuser_id,))
- return [{'id':row[0],'name':row[1]} for row in c]
+ return [{'id':row[0],'name':row[1], 'keyword':row[2]} for row in c]
def set_webuser_group(self, webuser_id, group_id):
c = self.cursor
@@ -396,7 +357,7 @@ def check_webuser_login(self, username, password):
if row:
hashed = row[1]
if bcrypt.hashpw(password, hashed) == hashed:
- return row[2],row[3]
+ return row[3],row[2]
return 0,0
class Doer:
View
@@ -12,6 +12,7 @@ def usage():
print("%s set-sender <number> <group>"%sys.argv[0])
print("%s set-admin <number> <group>"%sys.argv[0])
print("%s fake-incoming <src> <phone> <msg>"%sys.argv[0])
+ print("%s add-webadmin <login> <password>"%sys.argv[0])
sys.exit(1)
if len(sys.argv) < 2:
@@ -95,6 +96,11 @@ elif sys.argv[1] == 'fake-incoming':
print "number error!"
sys.exit(1)
data.fake_incoming(src,phone,msg)
+elif sys.argv[1] == 'add-webadmin':
+ if len(sys.argv) != 4:
+ usage()
+ login, password = sys.argv[2:]
+ data.add_webuser(login, password, 2)
else:
usage()
View
@@ -14,7 +14,9 @@ CREATE TABLE qq_groups (
id integer primary key autoincrement,
name varchar(50) not null,
keyword varchar(10) not null,
-phone varchar(22) not null);
+phone varchar(22) not null,
+unique (name, phone),
+unique (keyword, phone));
DROP TABLE IF EXISTS qq_webUsers;
CREATE TABLE qq_webUsers (
View
@@ -3,7 +3,7 @@
<div>
{% if session.userid %}
{% for group in groups %}
- <a href="{{ url_for('groups') }}{{group.name}}">{{ group.name }}</a>
+ <a href="{{ url_for('groups') }}{{group.name}}">{{ group.name }}({{ group.keyword }})</a>
{% else %}
<em>no groups</em>
{% endfor %}
@@ -32,7 +32,7 @@ <h2>{{name}}</h2>
</tr>
{% endfor %}
</table>
- <br>
+ <br><hr>
<b>add member</b>
<form action="{{ url_for('groups') }}{{ name }}" method=post class=add-member>
alias: <input type=text size=30 name=alias><br>
@@ -45,6 +45,7 @@ <h2>{{name}}</h2>
<b>add group</b>
<form action="{{ url_for('groups') }}" method=post class=add-group>
name: <input type=text size=30 name=name><br>
+ keyword: <input type=text size=30 name=keyword><br>
<input type=submit value=add>
</form>
{% endif %}
View
@@ -31,7 +31,7 @@
<input type=hidden value="{{ user.user_id }}" name=userid>
<select name=group>
{% for group in groups %}
- <option value={{ group.i }}>{{ group.name }}</option>
+ <option value={{ group.id }}>{{ group.name }}</option>
{% endfor %}
</select><input type=submit value=add></form></td>
<td><a href="{{ url_for('remove_webuser',uid=user.user_id) }}">delete user</a></td>
View
16 web.py
@@ -48,25 +48,26 @@ def groups(name=None):
group_id = data.get_group_id(name)
if group_id:
mid = data.add_number(number, request.form['alias'], group_id)
- if 'sender' in request.form:
- data.set_sender(config.default_phone, member_id=mid)
if 'admin' in request.form:
- data.set_admin(config.default_phone, member_id=mid)
+ data.set_member_info(mid, sender=True, admin=True)
+ elif 'sender' in request.form:
+ data.set_member_info(mid, sender=True)
else:
error = "group error!"
else:
error = "number error!"
else:
# add group
- gid = data.add_group(request.form['name'])
+ gid = data.add_group(request.form['name'], request.form['keyword'],
+ config.default_phone)
data.set_webuser_group(session.get('userid'), gid)
return redirect(url_for('groups')+request.form['name'])
members = None
if not session.get('admin'):
groups = data.get_webuser_groups(session.get('userid'))
else:
- groups = [{'id':g[0],'name':g[1]} for g in data.get_groups()]
+ groups = data.get_groups()
if name:
gid = data.get_group_id(name)
@@ -86,7 +87,7 @@ def remove_member(mid=None):
if not info:
abort(404)
- gids = [g.id for g in data.get_webuser_groups(session.get('userid'))]
+ gids = [g['id'] for g in data.get_webuser_groups(session.get('userid'))]
if not session.get('admin') and info['groupId'] not in gids:
abort(401)
@@ -123,7 +124,7 @@ def settings():
elif 'pw' in request.form:
data.set_webuser_pw(request.form['userid'], request.form['pw'])
- groups = [dict(i=row[0],name=row[1]) for row in data.get_groups()]
+ groups = data.get_groups()
return render_template('settings.html', webusers=data.get_webusers(),groups=groups)
@app.route('/removewebusergroup/<uid>/<gid>')
@@ -173,7 +174,6 @@ def logout():
flash('You were logged out')
return redirect(url_for('login'))
-
if __name__ == '__main__':
app.run()

0 comments on commit 621da54

Please sign in to comment.