def register(): if request.method == 'POST': name = request.form['name'] password = request.form['pass'] re_password = request.form['re_pass'] db = get_db() error = None if not name: error = 'Name is required' if not password: error = 'Password is required' if password != re_password: error = 'Check Passwords' elif db.execute('SELECT id FROM student WHERE username = ?', (name, )).fetchone() is not None: error = 'User {} is already registered.'.format(name) if error is None: db.execute( 'INSERT INTO student (id, username, password, user_type, user_dept, user_yr, phone_no) VALUES (?, ?, ?,?, ?,?,?)', (2173128, name, generate_password_hash(password), 'S', 'CSE', '2', '9096333107')) db.commit() flash(error) return redirect('auth.signin') return render_template('auth/signup.html')
def signin(): if request.method == 'POST': id = request.form['id'] password = request.form['pass'] db = get_db() error = None student = db.execute('SELECT * FROM student WHERE id = ?', (id, )).fetchone() if student is None: error = 'Incorrect username.' elif not check_password_hash(student['password'], password): error = 'Incorrect password.' if error is None: session.clear() session['user_id'] = student['id'] #return redirect(url_for('blog.index')) flash(error) return redirect(url_for('teacher.dashboard')) return render_template('auth/signin.html')
from app.model import get_db from app.hcprestricted import ad_bind, has_group_membership, config from app.hcpxnat.interface import HcpInterface """ Move to the root directory (same level as app/) to execute """ db = get_db() ldap = ad_bind() cdb = HcpInterface(url=config.get('hcpxnat', 'site'), username=config.get('hcpxnat', 'username'), password=config.get('hcpxnat', 'password')) users = cdb.getUsers() for u in users: if has_group_membership(u['login'], 'Phase2ControlledUsers'): print u['login'], "has restricted access." db.execute( "insert into restrictedaccess (firstname, lastname, email, login, status) \ values ('%s', '%s', '%s', '%s', 'Access Granted')" % \ (u['firstname'], u['lastname'], u['email'], u['login']) ) db.commit() db.close()
def tendency_results(): data = request.get_json() past_n = data['past_n'] db = get_db()['invitationCat'] t_now = datetime.datetime.today() t_at_zero = t_now.replace(hour=0, minute=0, second=0, microsecond=0) past_str = str(t_at_zero - datetime.timedelta(days=int(past_n))) pastn_time_array = time.strptime(past_str, '%Y-%m-%d %H:%M:%S') past_n_stamp = int(time.mktime(pastn_time_array) * 1000) past_str_one = str(t_at_zero - datetime.timedelta(days=int(past_n) - 1)) pastn_time_array_one = time.strptime(past_str_one, '%Y-%m-%d %H:%M:%S') past_n_stamp_one = int(time.mktime(pastn_time_array_one) * 1000) pastn_user_plays = db.actions.find({ 'behavior': 0, 'createdAt': { '$gte': float(past_n_stamp), '$lt': float(past_n_stamp_one) } }).count() #过去第n天观看 pastn_user_comments = db.comments.find({ 'status': '1', 'createdAt': { '$gte': float(past_n_stamp), '$lt': float(past_n_stamp_one) } }).count() #过去第n天评论 pastn_user_danmakus = db.danmakus.find({ 'status': '1', 'createdAt': { '$gte': float(past_n_stamp), '$lt': float(past_n_stamp_one) } }).count() #过去第n天弹幕 pastn_user_follows = db.follows.find({ 'type': { '$in': [1, 2, 3] }, 'createdAt': { '$gte': float(past_n_stamp), '$lt': float(past_n_stamp_one) } }).count() #过去第n天收藏 pastn_user_preferences = db.preferences.find({ 'state': 1, 'createdAt': { '$gte': float(past_n_stamp), '$lt': float(past_n_stamp_one) } }).count() #过去第n天点赞 pastn_user_shares = db.actions.find({ 'behavior': 6, 'createdAt': { '$gte': float(past_n_stamp), '$lt': float(past_n_stamp_one) } }).count() #过去第n天分享 all_tend_nums = pastn_user_plays + pastn_user_comments + pastn_user_danmakus + pastn_user_follows+\ pastn_user_preferences+pastn_user_shares return jsonify({ 'plays_n': { float(pastn_user_plays / all_tend_nums) * 100: '%' }, 'comments_n': { float(pastn_user_comments / all_tend_nums) * 100: '%' }, 'danmakus_n': { float(pastn_user_danmakus / all_tend_nums) * 100: '%' }, 'follows_n': { float(pastn_user_follows / all_tend_nums) * 100: '%' }, 'preferences_n': { float(pastn_user_preferences / all_tend_nums) * 100: '%' }, 'shares_n': { float(pastn_user_shares / all_tend_nums) * 100: '%' } })
def results(): ''' 获取用户数量、日用户活跃度、日观看活跃度、日观看活跃度 ''' db = get_db()['invitationCat'] playandshare_user = len( list( db.actions.aggregate([{ '$match': { 'behavior': { '$in': [0, 6] } } }, { '$project': { 'user': 1 } }, { '$group': { '_id': '$user' } }]))) comment_user = len( list( db.comments.aggregate([{ '$match': { 'status': '1' } }, { '$project': { 'user': 1 } }, { '$group': { '_id': '$user' } }]))) danmaku_user = len( list( db.danmakus.aggregate([{ '$match': { 'status': '1' } }, { '$project': { 'user': 1 } }, { '$group': { '_id': '$user' } }]))) follow_user = len( list( db.follows.aggregate([{ '$match': { 'type': { '$in': [1, 2, 3] } } }, { '$project': { 'user': 1 } }, { '$group': { '_id': '$user' } }]))) preference_user = len( list( db.preferences.aggregate([{ '$match': { 'state': 1 } }, { '$project': { 'user': 1 } }, { '$group': { '_id': '$user' } }]))) oneday_play_active = playandshare_user + comment_user + danmaku_user + follow_user + preference_user all_users = db.users.find({ 'userType': { '$in': ['entity', 'other'] } }).count() one_user_plays = db.actions.find({'behavior': 0}).count() one_user_comments = db.comments.find({'status': '1'}).count() one_user_danmakus = db.danmakus.find({'status': '1'}).count() one_user_follows = db.follows.find({'type': {'$in': [1, 2, 3]}}).count() one_user_preferences = db.preferences.find({'state': 1}).count() one_user_shares = db.actions.find({'behavior': 6}).count() one_nums = one_user_plays + one_user_comments + one_user_danmakus + one_user_follows+\ one_user_preferences + one_user_shares return jsonify({ 'all_users': all_users, 'oneday_active_users': oneday_play_active, 'oneday_play_active': { float(one_user_plays / one_nums) * 100: '%' }, 'oneday_active': { float((one_nums - one_user_plays) / one_nums) * 100: '%' } })