def update_courses(): moodle_api = MoodleApi(current_user.moodle_url, current_user.token) course_list = moodle_api.get_user_courses(current_user.moodle_id) user_course_list = [] for course_info in course_list: course = MoodleCourse.objects( moodle_id=course_info.get('moodle_id')).modify( moodle_id=course_info.get('moodle_id'), upsert=True, new=True) user_course_list.append(course) # update course forums course_forum_list = [] forum_list = moodle_api.get_course_forums(course.moodle_id) for forum_info in forum_list: forum = MoodleForum.objects( moodle_id=forum_info.get('moodle_id')).modify( moodle_id=forum_info.get('moodle_id'), course=course, upsert=True, new=True) forum.update_forum(forum_info).save() course_forum_list.append(forum) course.update_course(course_info).save() course.modify(forum_list=course_forum_list, forum_count=len(course_forum_list)) # save updated user in db current_user.modify(course_list=user_course_list) return jsonify(redirect_url=url_for('.show_all_courses'))
def account(): if current_user.is_authenticated: user_change = UpdateUsernameForm() picture_change = UpdateProfilePicForm() if user_change.validate_on_submit(): current_user.modify(username=user_change.username.data) current_user.save() return redirect(url_for('account')) if picture_change.validate_on_submit(): img = picture_change.picture.data filename = secure_filename(img.filename) content_type = f'images/{filename[-3:]}' if current_user.profile_pic.get() is None: current_user.profile_pic.put(img.stream, content_type=content_type) else: current_user.profile_pic.replace(img.stream, content_type=content_type) current_user.save() return redirect(url_for('account')) return render_template("account.html", nameform=user_change, picform=picture_change, image=current_user.get_b64_img())
def account(): search_form = SearchForm() if search_form.validate_on_submit(): return redirect( url_for("passwords.search_query", app_name=search_form.search_query.data)) master_form = UpdateMasterForm() if master_form.validate_on_submit(): # current_user.username = username_form.username.data current_user.modify(username=master_form.username.data, email=master_form.email.data) current_user.save() msg = Message( subject="Updated Email", sender="*****@*****.**", recipients=[current_user.email], body= "You have succesfully updated your username and email for password manager!" ) mail.send(msg) return redirect(url_for("users.account")) return render_template( "account.html", title="Account", master_form=master_form, search_form=search_form, )
def account(): username_form = UpdateUsernameForm() profile_pic_form = UpdateProfilePicForm() if username_form.validate_on_submit(): # current_user.username = username_form.username.data current_user.modify(username=username_form.username.data) current_user.save() return redirect(url_for("users.account")) if profile_pic_form.validate_on_submit(): img = profile_pic_form.propic.data filename = secure_filename(img.filename) if current_user.profile_pic.get() is None: current_user.profile_pic.put(img.stream, content_type='images/png') else: current_user.profile_pic.replace(img.stream, content_type='images/png') current_user.save() return redirect(url_for('users.account')) image = images(current_user.username) return render_template( "account.html", title="Account", username_form=username_form, profile_pic_form=profile_pic_form, image=image )
def account(): username_form = UpdateUsernameForm() profile_pic_form = UpdateProfilePicForm() if username_form.validate_on_submit(): # current_user.username = username_form.username.data temp = User.objects(username=current_user.username).first() msg = Message('Username Change', sender = '*****@*****.**', recipients = [str(temp.email)]) msg.body = "Your username has been updated!\nYour new username is: "+str(username_form.username.data) mail.send(msg) current_user.modify(username=username_form.username.data) current_user.save() return redirect(url_for('account')) if profile_pic_form.validate_on_submit(): img = profile_pic_form.propic.data filename = secure_filename(img.filename) if current_user.profile_pic.get() is None: current_user.profile_pic.put(img.stream, content_type='images/png') else: current_user.profile_pic.replace(img.stream, content_type='images/png') current_user.save() return redirect(url_for('account')) image = images(current_user.username) return render_template("account.html", title="Account", username_form=username_form, profile_pic_form=profile_pic_form, image=image)
def account(): username_form = UpdateUsernameForm() profile_pic_form = UpdateProfilePicForm() # We have to make sure the form was actually submitted before validating since we have 2 forms on one page if username_form.username.data is not None and username_form.submit.data and username_form.validate_on_submit(): current_user.modify(username=username_form.username.data) current_user.save() login_user(current_user) return redirect(url_for('users.account')) if profile_pic_form.propic.data is not None and profile_pic_form.validate_on_submit(): img = profile_pic_form.propic.data filename = secure_filename(img.filename) if current_user.profile_pic.get() is None: current_user.profile_pic.put(img.stream, content_type='images/png') else: current_user.profile_pic.replace(img.stream, content_type='images/png') current_user.save() return redirect(url_for('users.account')) image = images(current_user.username) return render_template("account.html", title="Account", username_form=username_form, profile_pic_form=profile_pic_form, image=image)
def account(username): if current_user.is_authenticated: print("user auth true") updateUsernameForm = UpdateUsernameForm() postItemForm = PostItemForm() updatePhotoForm = UpdateProfilePicForm() if request.method == "POST": print("hit post method") submitter = request.form['submit'] if submitter == "Update Username": #USERNAME UPDATE FORM if updateUsernameForm.submit.data: if updateUsernameForm.validate_on_submit(): newUsername = updateUsernameForm.username.data current_user.modify(username=newUsername) current_user.save() return redirect(url_for("bpUser .logout")) if submitter == "Publish your listing": #POSTING A PROPERTY FORM if postItemForm.submit.data: if postItemForm.validate_on_submit(): item = Item( poster=current_user._get_current_object(), price=postItemForm.price.data, rooms=postItemForm.rooms.data, restrooms=postItemForm.restrooms.data, propertyType=postItemForm.propertyType.data, description=postItemForm.description.data, date=current_time()) item.save() return redirect(url_for("bpItem.index")) if submitter == 'Update profile picture': # CHECKING FOR PRO-PIC UPDATE FORM print("submitter:", submitter) if updatePhotoForm.submit.data: print("photo form data:", updatePhotoForm.submit.data) if updatePhotoForm.validate_on_submit(): print("photo form validated") img = updatePhotoForm.photo.data print("img: ", img) filename = secure_filename(img.filename) print("filename:", filename) contentType = f'images/{filename[-3:]}' print("contentType: ", contentType, filename[-3:], img) print(".get(): ", current_user.profilePic.get()) if current_user.profilePic.get() is None: print("current_user.profilePic.get() is none") current_user.profilePic.replace( img.stream, contentType=contentType) print("after ") else: print("current_user.profilePic.get() was not None") current_user.profilePic.replace( img.stream, contentType=contentType) current_user.save() print("gonna hit final render") return render_template("account.html", title="Account", updateUsernameForm=updateUsernameForm, updatePhotoForm=updatePhotoForm, image=get_b64_img(current_user.username), postItemForm=postItemForm)
def account(): username_form = UpdateUsernameForm() password_form = UpdatePasswordForm() profile_pic_form = UpdateProfilePicForm() if password_form.validate_on_submit(): hashed = bcrypt.generate_password_hash( password_form.new_password.data).decode("utf-8") msg = Message('Password Change', sender='*****@*****.**', recipients=[str(temp.email)]) msg.body = "Your password has been updated! Please reply to this e-mail if you did not request this change." mail.send(msg) current_user.modify(password=hashed) current_user.save() return redirect(url_for('users.account')) if username_form.validate_on_submit(): temp = User.objects(username=current_user.username).first() current_user.username = username_form.username.data msg = Message('Username Change', sender='*****@*****.**', recipients=[str(temp.email)]) msg.body = "Your username has been updated!\nYour new username is: " + str( username_form.username.data) mail.send(msg) current_user.modify(username=username_form.username.data) current_user.save() return redirect(url_for('users.account')) if profile_pic_form.validate_on_submit(): img = profile_pic_form.propic.data filename = secure_filename(img.filename) if current_user.profile_pic.get() is None: current_user.profile_pic.put(img.stream, content_type='images/png') else: current_user.profile_pic.replace(img.stream, content_type='images/png') current_user.save() return redirect(url_for('users.account')) image = images(current_user.username) return render_template("account.html", title="Account", username_form=username_form, password_form=password_form, profile_pic_form=profile_pic_form, image=image)
def account(): form = UpdateUsernameForm() if form.validate_on_submit(): # update username field in db current_user.modify(username=form.username.data) current_user.save() return redirect(url_for('account')) return render_template('account.html', form=form)
def account(): form = UpdateUsernameForm() if form.validate_on_submit(): if len(User.objects(username=form.username.data)) == 0: current_user.modify(username=form.username.data) current_user.save() return redirect(url_for('account')) else: flash('This username is already taken!') return render_template('account.html', form=form, user=current_user)
def account(): username_form = UpdateUsernameForm() if username_form.validate_on_submit(): current_user.modify(username=username_form.username.data) current_user.save() return redirect(url_for("users.account")) return render_template( "account.html", title="Account", username_form=username_form, )
def update_courses(): stepic_api = StepicApi(current_user.token) course_list = stepic_api.get_user_courses(current_user.stepic_id) user_course_list = [] for course_info in course_list: course = StepicCourse.objects( stepic_id=course_info.get('stepic_id')).modify( stepic_id=course_info.get('stepic_id'), upsert=True, new=True) user_course_list.append(course) course.update_course(course_info).save() current_user.modify(course_list=user_course_list) return jsonify(redirect_url=url_for('.show_all_courses'))
def account(username): username_form = UpdateUsernameForm() password_form = UpdatePasswordForm() if username_form.validate_on_submit(): print(current_user.username) current_user.modify(username=username_form.username.data) current_user.save() return redirect(url_for('users.account', username=current_user.username)) if password_form.validate_on_submit(): hashed = bcrypt.generate_password_hash(password_form.password.data).decode("utf-8") current_user.modify(password=hashed) current_user.save() return redirect(url_for('users.account', username=current_user.username)) return render_template('account.html', username_form=username_form, password_form=password_form)
def account(): username_form = UpdateUsernameForm() if username_form.validate_on_submit(): # current_user.username = username_form.username.data mongo_lock.acquire() current_user.modify(username=username_form.username.data) current_user.save() mongo_lock.release() return redirect(url_for('users.account')) mongo_lock.acquire() user = User.objects(username=current_user.username).first() mongo_lock.release() return render_template("account.html", title="Account", username_form=username_form, user=user)
def account(): form = UpdateUsernameForm() if form.validate_on_submit(): if len(User.objects(username=form.username.data)) == 0: current_user.modify(username=form.username.data) current_user.save() msg = Message( "You changed your username!", recipients=User.objects( username=current_user.username).first().email.split()) username = current_user.username msg.body = "You changed your username to " + username mail.send(msg) return redirect(url_for('loginpage.account')) else: flash('This username is already taken!') return render_template('account.html', form=form, user=current_user)
def account(): usernameForm = UpdateUsernameForm() profileForm = UpdateProfilePicForm() if usernameForm.validate_on_submit(): try: usernameForm.validate_username(usernameForm.username) current_user.modify(username=usernameForm.username.data) current_user.save() except ValueError as e: return render_template("account.html", error_msg = str(e), username=current_user.username, image=get_b64_img(current_user.profile_pic.read()), usernameForm=usernameForm, profileForm=profileForm) if profileForm.validate_on_submit(): img = profileForm.picture.data filename = secure_filename(img.filename) content_type = f'images/{filename[-3:]}' current_user.profile_pic.replace(img.stream, content_type=content_type) current_user.save() return render_template("account.html", username=current_user.username, image=get_b64_img(current_user.profile_pic.read()), usernameForm=usernameForm, profileForm=profileForm)
def game_detail(game_id): result = sport_client.getEventByID(game_id) if type(result) == dict: return render_template( 'game_detail.html', error_msg=f'{result["Error"]}. Game ID {game_id}') subscription_form = NotificationSubscriptionForm() unsubscription_form = NotificationUnsubscriptionForm() comment_form = GameCommentForm() if comment_form.validate_on_submit(): comment = Comment( commenter=load_user(current_user.username), content=comment_form.text.data, date=current_time(), game_id=game_id, ) mongo_lock.acquire() comment.save() mongo_lock.release() return redirect(request.path) subscribed = False mongo_lock.acquire() if current_user.is_authenticated and User.objects( username=current_user.username).first().game_subscriptions.count( int(game_id)) is not 0: subscribed = True mongo_lock.release() if subscribed and unsubscription_form.validate_on_submit(): mongo_lock.acquire() user = User.objects(username=current_user.username).first() new_subscriptions = user.game_subscriptions new_subscriptions.remove(int(game_id)) current_user.modify(game_subscriptions=new_subscriptions) mongo_lock.release() return redirect(request.path) if not subscribed and subscription_form.validate_on_submit(): mongo_lock.acquire() user = User.objects(username=current_user.username).first() current_user.modify(game_subscriptions=user.game_subscriptions + [game_id]) mongo_lock.release() return redirect(request.path) mongo_lock.acquire() comments_m = Comment.objects(game_id=game_id) mongo_lock.release() comments = [] for r in comments_m: comments.append({ 'date': r.date, 'username': r.commenter.username, 'content': r.content, }) return render_template('game_detail.html', comment_form=comment_form, game=result, comments=comments, subscription_form=subscription_form, unsubscription_form=unsubscription_form, subscribed=subscribed)
def modify_profile(): current_user.modify(request.json) ApiHandler.save(current_user) return jsonify(as_dict(current_user, includes=USER_INCLUDES)), 200
def account(): password_form = UpdatePasswordForm() add_form = AddUserForm() delete_user_form = DeleteUserForm() changeapikeyform = ChangeAPIKeyForm() if request.form.get('submit_btn') == 'Change Password' and password_form.validate_on_submit() \ and current_user.is_authenticated: hashed = bcrypt.generate_password_hash( password_form.password.data).decode("utf-8") current_user.modify(password=hashed) current_user.save() flash("Password changed.", "top-success") return redirect(url_for("users.account")) if request.form.get('submit_btn') == 'Add' and add_form.validate_on_submit() and current_user.is_authenticated \ and current_user.level < 2 and current_user.level < int(add_form.level.data): hashed = bcrypt.generate_password_hash( add_form.password.data).decode("utf-8") username = add_form.username.data if User.objects(username=add_form.username.data).first(): flash("User '" + username + "' already exists.", "bottom-warning") else: api_key = secrets.token_urlsafe(32) if add_form.level < 2 else None user = User(username=username, password=hashed, level=add_form.level.data, api_key=api_key) user.save() flash("User '" + username + "' added.", "bottom-success") return redirect(url_for("users.account")) if request.form.get('submit_btn') == 'Delete' and delete_user_form.validate_on_submit() \ and current_user.is_authenticated and current_user.level < 2: username = delete_user_form.username.data user = User.objects(username=delete_user_form.username.data).first() if user is None: flash("User '" + username + "' does not exist.", "bottom-warning") elif current_user.level <= user.level: user.delete() flash("User '" + username + "' deleted.", "bottom-success") return redirect(url_for("users.account")) if request.form.get('submit_btn') == 'Change' and changeapikeyform.validate_on_submit() \ and current_user.is_authenticated and current_user.level < 2: current_user.modify(api_key=secrets.token_urlsafe(32)) current_user.save() flash("API key changed.", "top-success") return redirect(url_for("users.account")) users = list(User.objects()) users.sort(key=lambda x: (x.level, x.username.lower())) metadata = Metadata(title="Account", description="") return render_template("account.html", title="Account", searchform=SearchForm(), password_form=password_form, addform=add_form, deleteuserform=delete_user_form, changeapikeyform=changeapikeyform, users=users, searchtags=getSearchTags(), metadata=metadata)