def mygroups(type='js'): if 'user' in session and 'joinInfos' in session['user']: connect = MySQLdb.connect(db=config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, user=config.DB_USER, passwd=config.DB_PASSWD) resp = render_template('mygroups.html', username = session['user']['uname'], groups = GroupService.getMyGroups(session['user'], connect)) connect.close() return resp return redirect(url_for('login_view'))
def member_reg_view(gid,key): connect = MySQLdb.connect(db=config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, user=config.DB_USER, passwd=config.DB_PASSWD) group = GroupService.getGroup(None, gid, connect) connect.close() if group == None or not key == hash(int(gid)): return render_template('request_deny.html') if 'user' in session: return render_template('member_join.html', group_id=gid, group=group) else: return render_template('member_reg.html', group_id=gid, group=group)
def groups(): if 'user' in session and 'joinInfos' in session['user']: connect = MySQLdb.connect(db=config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, user=config.DB_USER, passwd=config.DB_PASSWD) result = GroupService.getComunity(session['user'], connect) connect.close() for g in result: g['url'] = '/member_reg/'+str(g['id'])+'/'+str(hash(g['id'])) return render_template('groups.html', username = session['user']['uname'], groups = result) return redirect(url_for('login_view'))
def login_to_group_view(key): if request.method == 'GET': if 'user' in session and 'group' in session['user'] and session['user']['group']['key'] == key: return redirect('/group/'+key) else: connect = MySQLdb.connect(db=config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, user=config.DB_USER, passwd=config.DB_PASSWD) group = GroupService.getGroupByKey(key, connect) connect.close() return render_template('login_to_group.html', group=group) elif request.method == 'POST': result = UserService.LoginToGroup(request.form['username'], request.form['password'], key) return json.dumps(result) else: return render_template('login_to_group.html', group=group)
def update_role(): if 'user' in session: connect = MySQLdb.connect(db=config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, user=config.DB_USER, passwd=config.DB_PASSWD) result = GroupService.updateRole(session['user'], request.form['group_id'], request.form['user_id'], request.form['role'], connect) connect.close() return json.dumps(result)
def update_group(): if 'user' in session: connect = MySQLdb.connect(db=config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, user=config.DB_USER, passwd=config.DB_PASSWD) result = GroupService.updateGroup(session['user'], request.form['group_id'], request.form['name'].encode('utf-8'), request.form['detail'].encode('utf-8'), request.form['visibillity'], connect) connect.close() return json.dumps(result)