def account(): name = current_user.__getattr__(name="username") email = current_user.__getattr__(name="email") password = current_user.__getattr__(name="password") form = UpdateAccountForm() if form.validate_on_submit(): current_user.username = form.username.data current_user.send_email = form.email.data db.session.commit() flash('Your account has been updated!', 'success') return redirect(url_for('account')) # This populates our form with the current users data elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.send_email # TODO put this back image_file = url_for('static', filename='static/' + current_user.image_file) image_file = 'static/default.jpg' return render_template('account.html', title='Account', name=name, email=email, image_file=image_file, password=password, form=form)
def app_upload(): file = request.files['file'] basePath = os.path.join('/data', current_user.__getattr__('name'), 'source') if not os.path.exists(basePath): os.makedirs(basePath) os.chmod(basePath, mode=0o777) uploadPath = os.path.join(basePath, secure_filename(os.path.splitext(file.filename)[0]+'-'+str(datetime.now().strftime("%Y/%m/%d-%H:%M:%S"))+os.path.splitext(file.filename)[1])) if uploadPath.endswith(('.mp4', '.mkv', '.avi', '.wmv', '.iso')): file.save(uploadPath) uploadPath = str(uploadPath.replace("\\", "/")) username = current_user.__getattr__('name') threading.Thread(target=run_detection, args=(0.5, 0.5, uploadPath, file.filename, username, 'true'), daemon=True).start() # future = executor.submit(run_detection, 0.5, 0.5, uploadPath, file.filename, username) return jsonify({'code': 0, 'errmsg': "Upload Success!"}) else: return jsonify({'code': -1, 'errmsg': "Upload Failed!"})
def refresh_notification(): # count the unread message number user = User.query.filter_by(name=current_user.__getattr__('name')).first() messages = {} counter = user.new_messages(user.last_message_read_time) messages[0] = counter return json.dumps(messages)
def reset(): # reset password after the user login user = User.query.filter_by(name=current_user.__getattr__('name')).first() if request.method == "POST": user_info = request.form.to_dict() if user_info.get("password") == user_info.get("rpassword"): user.set_password(user_info.get("password")) db.session.commit() return render_template('account.html', user=user) else: flash('Passwords are different') return render_template('reset.html', user=user)
def upload(): if request.method == "GET": return render_template('upload.html', title='Upload File') else: file = request.files['file'] basePath = os.path.join('/data', current_user.__getattr__('name'), 'source') # basePath = os.path.join(os.getcwd(), current_user.__getattr__('name'), 'source') if not os.path.exists(basePath): os.makedirs(basePath) os.chmod(basePath, mode=0o777) uploadPath = os.path.join(basePath, secure_filename(os.path.splitext(file.filename)[0]+'-'+str(datetime.now().strftime("%Y/%m/%d-%H:%M:%S"))+os.path.splitext(file.filename)[1])) # check file type if uploadPath.endswith(('.mp4', '.mkv', '.avi', '.wmv', '.iso')): file.save(uploadPath) uploadPath = str(uploadPath.replace("\\", "/")) username = current_user.__getattr__('name') # asynchronous process threading.Thread(target=run_detection, args=(0.5, 0.5, uploadPath, file.filename, username, 'false'), daemon=True).start() flash('File upload successfully') else: flash('Error file format') return redirect(url_for('upload'))
def app_history(): user = User.query.filter_by(name=current_user.__getattr__('name')).first() data = db.session.query(History, Video).filter(History.video_id == Video.id).filter_by(user_id=user.id, status=1).all() history = [] # packing the information into json format for h in data: temp = {} temp['history_id'] = h.History.id temp['user_id'] = h.History.user_id temp['count'] = h.History.count temp['video_id'] = h.History.video_id temp['submit_time'] = h.History.submit_time.strftime("%Y/%m/%d, %H:%M") temp['status'] = h.History.status temp['location'] = h.Video.location temp['name'] = h.Video.name history.append(temp) return jsonify({'code': 0, 'errmsg': history})
def retrieve_notification(): user = User.query.filter_by(name=current_user.__getattr__('name')).first() # judge the time of last reading of user if user.last_message_read_time is None: notifications = Message.query.filter_by(user_id=user.id, ).all() else: notifications = Message.query.filter_by(user_id=user.id, )\ .filter(Message.time_stamp > user.last_message_read_time).all() # update last reading time user.last_message_read_time = datetime.now() db.session.flush() db.session.commit() messages = {} counter = 0 # packing the information into json format for msg in notifications: messages[counter] = msg.to_json() counter = counter + 1 return json.dumps(messages)
def article(): # form提交 if not current_user.is_authenticated: flash('请先登录') return redirect(url_for('login')) if request.method == 'POST': data = dict(request.form) print('current_user', current_user.__dict__) dict_target = {} for key, val in data.items(): if key in column_name_list(Article): dict_target[key] = val record = Article(**dict_target) record.author_id = current_user.__getattr__('id') db.session.add(record) db.session.commit() return redirect(url_for('article')) article_list = Article.query.all() return render_template('article.html', article=article_list)
def user_settings(): session_data = mast.session.Session() update_profile_form = UpdateProfileForm(name='up') display_update_profile_form = 'none' change_password_form = ChangePasswordForm(name='chp') display_change_password_form = 'none' if request.method == 'POST': if request.form['submit'] == 'Update profile': update_profile_form = UpdateProfileForm(request.form) if update_profile_form.validate(): current_user.complete_profile( first_name=update_profile_form.first_name.data.strip(), last_name=update_profile_form.last_name.data.strip(), age=update_profile_form.age.data, sex=update_profile_form.sex.data, shirt_size=update_profile_form.shirt_size.data, user_type=update_profile_form.user_type.data, ukco=update_profile_form.ukco.data.strip(), display_name=update_profile_form.display_name.data.strip(), anonymous=update_profile_form.competing.data) if authenticate_via_sis(name=current_user.first_name, surname=current_user.last_name, login=None, uk_id=current_user.uk_id, is_employee=current_user.type.value): current_user.verify() session_data.info('Your profile has been been verified.') return redirect(url_for('users.user_settings')) else: session_data.warning( 'Your profile has not been been verified.<br />' + 'We will verify your profile in a few days if you are sure with your data.' ) else: # Keep the form visible if it contains errors display_update_profile_form = 'block' elif request.form['submit'] == 'Update password': change_password_form = ChangePasswordForm(request.form) if change_password_form.validate(): hashed_password = bcr.generate_password_hash( change_password_form.password.data).decode('UTF-8') current_user.change_password(hashed_password) session_data.info('Your password has been changed.') return redirect(url_for('users.user_settings')) else: # Keep the form visible if it contains errors display_change_password_form = 'block' # For GET and after POST method check_profile_verified(session_data) for key, data in update_profile_form.data.items(): if key in ["first_name", "last_name", "display_name"]: update_profile_form[key].data = current_user.__getattr__(key) or '' update_profile_form.ukco.data = current_user.uk_id or '' update_profile_form.age.data = current_user.age.value if current_user.age else None update_profile_form.sex.data = current_user.sex.value if current_user.sex else None update_profile_form.shirt_size.data = current_user.shirt_size or None update_profile_form.user_type.data = current_user.type.value if current_user.type else None update_profile_form.competing.data = current_user.anonymous or None return render_template( "user_settings.html", title='User Settings', profile=current_user, update_profile_form=update_profile_form, display_update_profile_form=display_update_profile_form, change_password_form=change_password_form, display_change_password_form=display_change_password_form, session_data=session_data)
def app_account(): user = User.query.filter_by(name=current_user.__getattr__('name')).first() # return jsonify({'code': 0, 'user': user.to_json()}) return jsonify({'code': 0, 'user': user.get_json()})
def account(): user = User.query.filter_by(name=current_user.__getattr__('name')).first() return render_template('account.html', user=user)
def history(): user = User.query.filter_by(name=current_user.__getattr__('name')).first() histories = db.session.query(History, Video).filter(History.video_id == Video.id).filter_by(user_id=user.id, status=1).all() return render_template('history.html',histories=histories)