def allblog(email,_id): if utils.email_is_valid(email) == True and 'user' in session and session['login_email'] == email: ids = Users.id_one_user(_id)['_id'] blog_id = Users.get_by_email(email)['_id'] dataemail = Users.bgemail_one(request.cookies.get('login_email')) dataemail = Users.get_by_email(session['user'])['email'] if email == dataemail: return redirect(url_for('memebership',email=dataemail,_id=_id)) else: flash("not good") render_template('page_not_found.html') return render_template('page_not_found.html')
def reqs(email): if Users.get_by_email(email): return render_template('resetpass.html', email=email, confirmEmail='True') else: return render_template('login.html')
def register_process(): regform = Form(request.form) if request.method == 'POST' and request.cookies.get('login_email') is None: print(request.form['firstname']) reg = RegisterForm(request.form['firstname'],request.form['lastname'],request.form['email'],request.form['password'],request.form['confirm'],request.files['file']) size=128 dig = md5(request.form['email'].lower().encode('utf-8')).hexdigest() image = 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format(dig, size) user_name = request.form['firstname'].lower() f = reg.filename filename = secure_filename(f.filename) email = request.form['email'].lower() password = request.form['password'].lower() confirm = request.form['confirm'].lower() if Users.get_by_email(request.form['email'].lower()) != True and reg.PasswordMatch(password, confirm) == True and reg.notEmpty() == True: mail = Mail("*****@*****.**", email) mail.sendMail() f.save(os.path.join(os.getcwd() +'/static/uploads/reg', filename)) print(reg.notEmpty()) Users.registration(request.form['firstname'], request.form['lastname'] , request.form['email'], request.form['password'], request.files['file'].filename, image=image) return redirect(url_for('success_full_reg')) else: flash("One or more inputs is empty or ") flash("There is a user with that email") flash("please make sure every input is entered") return render_template('register.html', title='register', regform=regform) flash("There is a problem") return render_template('register.html', title='register', regform=regform)
def activated(): User_utils = utils() loginform = LoginForm() if request.method == 'POST' and request.cookies.get('login_email') == "": password = request.form['password'] email = request.form['email'] database_email = Users.get_by_email(request.form['email']) database_password = Users.get_by_password(email, password) user_active = Users.get_by_active(request.form['email']) if database_email and password != "" and database_password == True: if not user_active: Database.updates("user", {"email": email}, {"$set": { "active": 1 }}) print("activated %d") flash("Thank you for activating you account") return render_template("login.html", loginform=loginform) flash("Please enter correct information inorder to activate account") return render_template("activate.html", loginform=loginform)
def changepass(): session.pop('_flashes', None) if request.method == 'POST': if Users.get_by_email(request.form['email']) == True: if request.form['email'] != None: response = make_response(redirect(url_for('reqs', email=request.form['email']))) response.set_cookie('password_email', request.form['email']) return response else: return render_template('login.html')
def editeprocess(email,blogtitle,blog_id): editeform = EditeForm() loginform = LoginForm() database_email = Users.get_by_email(email)["email"] if editeform.validate_on_submit() == True and 'user' in session and session['user'] == email and blog_id.__len__() == 32: thins = Users.bytitle(blogtitle) ids = Users.id_one(blog_id)["_id"] for stuff in thins: if stuff['titleblog'] == blogtitle and stuff['email'] == session["user"] and blog_id == ids: description = editeform.description.data Database.updates("blogs",{"content":stuff['content']},{"$set": {"content":description}}) return render_template('editemessage.html') else: redirect(url_for('login')) flash("these are technical errors please try login again") return render_template('login.html',loginform=loginform)
def edite(email,titleblog,blog_id): properties = [] editeform = EditeForm() loginform = LoginForm() if 'user' in session and session['user'] == email and blog_id and utils.email_is_valid(email) == True and blog_id.__len__() == 32: data_id = Users.get_by_email(email)["_id"] content = Users.bytitle(titleblog) for stuffs in content: ids = Users.id_one(blog_id)["_id"] if session['user'] == email and blog_id == ids: editeform.description.data = stuffs['content'] return render_template('edite.html',editeform=editeform,email=email,blogtitle=titleblog,blog_id=blog_id) else: flash("checking problem") return redirect(url_for('login')) return redirect(url_for('login'))
def blog(): blogform = BlogForm(request.form['author'], request.form['title'],request.form['email'],request.cookies.get('login_id'),request.form['description'], request.files['file']) if request.method == 'POST' and request.cookies.get('login_email') is not None: author = blogform.author title = blogform.title email = blogform.email description = blogform.description titleblog = title.lower() f = blogform.filename filename = secure_filename(f.filename) f.save(os.path.join(os.getcwd() +'/static/uploads', filename)) print(Users.blogExists(request.form['title'])) if Users.blogExists(request.form['title']) == False: userImage = Database.find_one("user", {"firstname":author})['image'] cookie = request.cookies.get('login_email') person = Users.get_by_email(cookie) blog = Blogs(author=author,titleblog=titleblog,description=description,email=email,filename=filename, userImage=userImage) blog.save_to_mongo() if request.cookies.get('login_email') == email: data = Database.find_one(UserConstants.COLLECTION,{"email":email}) flash('you have successfull created a blog') response = make_response(redirect(url_for('welcome', author=data["firstname"], lastname=data['lastname'], email=request.form['email']))) response.set_cookie('login_email', request.form['email']) response.set_cookie('login_author', data['firstname']) response.set_cookie('login_id', data['_id']) return response else: return render_template('blogform.html',point=blogform.message("A blog with that name already exist") ) else: return render_template('blogform.html',point=blogform.message("A blog with that name already exist")) return redirect(url_for('login_route'))
def UserExist(user): UserTrue = Users.get_by_email(user) if UserTrue is not None: return UserTrue else: return False