def log_the_user_in(mail): uid=None try: conn = sqlite3.connect(app.config['DATABASE']) print "Got here login user" if conn is not None: print "connection in login user" cur = conn.cursor() print "cursor in login user"+mail cur.execute("SELECT * from wishlist_users where email=?",[mail]) print "Got here" row = cur.fetchone() if row is not None: print "Got here" uid=row[0] print "fetched wishlist" session['email'] = request.form['email'] print "fetched wishlist" cur.execute("SELECT * from wishlist_set where id=?",[uid]) wish_list = cur.fetchall() return redirect(url_for('view_list', uid=uid,wish_list=wish_list)) else: raise ValueError except: error="Failed to login user" return redirect(url_for('login', error=error))
def board_write(): if session["id"] is None or session["id"] == "": return redirect(url_for("board.member_login")) if request.method == "POST": #name = request.form.get("name") writer_id = session.get("id") title = request.form.get("title") contents = request.form.get("contents") current_utc_time = round(datetime.utcnow().timestamp() * 1000) board = mongo.db.board post = { "writer_id": writer_id, "name": session["name"], "title": title, "contents": contents, "view": 0, "pubdate": current_utc_time, } x = board.insert_one(post) return redirect(url_for("board.board_view", idx=x.inserted_id)) else: return render_template("write.html", name=session["name"], title="글 작성")
def board_edit(idx): if request.method == "GET": board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data is None: flash("해당 게시물이 존재하지 않습니다.") return redirect(url_for("board.lists")) else: if session.get("id") == data.get("writer_id"): return render_template("edit.html", data=data, title="글 수정") else: flash("글 수정 권한이 없습니다.") return redirect(url_for("board.lists")) else: title = request.form.get("title") contents = request.form.get("contents") board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data.get("writer_id") == session.get("id"): board.update_one({"_id": ObjectId(idx)}, { "$set": { "title": title, "contents": contents, } }) flash("수정되었습니다.") return redirect(url_for("board.board_view", idx=idx)) else: flash("글 수정 권한이 없습니다.") return redirect(url_for("board.lists"))
def project_write(): col = mongo.db.version_list_customer data = col.find({}).sort("pubdate",-1) if request.method == "POST": project_name1 = request.form.get("project_name1") project_name2 = request.form.get("project_name2") name = request.form.get("name") startdate = request.form.get("startdate") enddate = request.form.get("enddate") author = request.form.get("author") current_utc_time = round(datetime.utcnow().timestamp() * 1000) post = { "project_name1" : project_name1, "project_name2" : project_name2, "name" : name, "startdate" : startdate, "enddate" : enddate, "author" : author, "pubdate": current_utc_time, } col.insert_one(post) return redirect(url_for("project.project_write", data=data)) else: return render_template("project_write.html", data=data)
def beam_result(): """ Fast estimate Wall """ data = dict(doc_id=uu_id('item')) data['tag'] = request.form.get('tag') data['wall_tag'] = request.form.get('wall_tag') data['width'] = request.form.get('width') data['depth'] = request.form.get('depth') data['length'] = request.form.get('length') data['amount'] = request.form.get('amount') data['category'] = Category.query.get_or_404(request.form.get('category')) data['topbar'] = request.form.get('topbar') data['midbar'] = request.form.get('midbar') data['botbar'] = request.form.get('botbar') data['stirup'] = request.form.get('stirup') data['topbar_amt'] = request.form.get('topbar_amt') data['midbar_amt'] = request.form.get('midbar_amt') data['botbar_amt'] = request.form.get('botbar_amt') data['stirup_spacing'] = request.form.get('stirup_spacing') beam = Beam(data['doc_id'], data['tag'], data['wall_tag'], data['width'], data['depth'], data['length'], data['amount'], data['category'], data['topbar'], data['midbar'], data['botbar'], data['stirup'], data['stirup_spacing'], data['topbar_amt'], data['midbar_amt'], data['botbar_amt']) db.session.add(beam) db.session.commit() flash('Beam {} added to project!'.format(data['tag']), 'success') return redirect(url_for('index.getwall'))
def project_edit(): idx = request.args.get("idx") project_name1 = request.form.get("project_name1") project_name2 = request.form.get("project_name2") name = request.form.get("name") startdate = request.form.get("startdate") enddate = request.form.get("enddate") author = request.form.get("author") col = mongo.db.version_list_customer col.update_one({"_id": ObjectId(idx)}, { "$set": { "project_name1": project_name1, "project_name2": project_name2, "name": name, "startdate": startdate, "enddate": enddate, "author": author, } }) flash("수정되었습니다.") return redirect(url_for("project.project_write"))
def column_result(): """ Fast estimate Column """ data = dict(doc_id=uu_id('item')) data['tag'] = request.form.get('tag') data['wg_tag'] = request.form.get('wg_tag') data['category'] = Category.query.get_or_404(request.form.get('category')) data['width'] = request.form.get('width') data['depth'] = request.form.get('depth') data['height'] = request.form.get('height') data['amount'] = request.form.get('amount') data['mainbar'] = request.form.get('main_bar_type') data['compositebar'] = request.form.get('composite_bar_type') data['stirup'] = request.form.get('stir_bar_type') data['mainbar_amt'] = request.form.get('main_bar_amt') data['compositebar_amt'] = request.form.get('composite_bar_amt') data['stirup_spacing'] = request.form.get('stir_spacing') column = Column(data['doc_id'], data['tag'], data['wg_tag'], data['category'], data['width'], data['depth'], data['height'], data['amount'], data['mainbar'], data['compositebar'], data['stirup'], data['stirup_spacing'], data['mainbar_amt'], data['compositebar_amt']) db.session.add(column) db.session.commit() flash('Beam {} added to project!'.format(data['tag']), 'success') return redirect(url_for('index.getwall'))
def category_create(): if request.method == 'POST': name = request.form.get('name') category = Category(name) db.session.add(category) db.session.commit() flash('Category {} created has been created!'.format(name), 'success') return redirect(url_for('index.create_category'))
def board_delete(idx): board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data.get("writer_id") == session.get("id"): board.delete_one({"_id": ObjectId(idx)}) flash("삭제 되었습니다.") else: flash("글 삭제 권한이 없습니다.") return redirect(url_for("board.lists"))
def admin(): # Check if admin is logged-in if not admin_loggedin(): return redirect(url_for('login')) msg = '' # Retrieve all accounts from the database cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) cursor.execute('SELECT * FROM accounts') accounts = cursor.fetchall() return render_template('admin/index.html', accounts=accounts)
def save_termform_clip(form): ''' Helper function that takes a TermForm with create_clip_with_file uploaded by the user, saves the file to disk, and returns the URL to that file (which should be used as the URL for a new Clip). ''' destination_fname = (''.join([random.choice('abcdefghijklmnopqrstuvwzyz') for x in range(0, 16)])) + \ (os.path.splitext(form.create_clip_with_file.data.filename)[1]) destination_path = os.path.join(sys.path[0], 'static', 'clips', destination_fname) destination_url = url_for('static', filename=os.path.join('clips', destination_fname)) form.create_clip_with_file.data.save(destination_path) return destination_url
def admin_emailtemplate(): # Check if admin is logged-in if not admin_loggedin(): return redirect(url_for('login')) # Get the template directory path template_dir = os.path.join(os.path.dirname(__file__), 'templates') # Update the template file on save if request.method == 'POST': content = request.form['content'].replace('\r', '') open(template_dir + '/activation-email-template.html', mode='w', encoding='utf-8').write(content) # Read the activation email template content = open(template_dir + '/activation-email-template.html', mode='r', encoding='utf-8').read() return render_template('admin/email-template.html', content=content)
def wall_opening(): """ Fast estimate Wall """ data = dict(doc_id=uu_id('item')) data['tag'] = request.form.get('tag') data['wall_tag'] = request.form.get('wall_tag') data['width'] = request.form.get('width') data['height'] = request.form.get('height') data['amount'] = request.form.get('amount') data['category'] = Category.query.get_or_404(request.form.get('category')) opening = Opening(data['tag'], data['wall_tag'], data['width'], data['height'], data['amount'], data['category'], data['doc_id']) db.session.add(opening) db.session.commit() flash('Opening {} added to project!'.format(data['tag']), 'success') return redirect(url_for('index.getwall'))
def foundation_result(): """ Fast estimate Foundation """ data = dict(doc_id=uu_id('item')) data['tag'] = request.form.get('tag') data['wg_tag'] = request.form.get('wg_tag') data['category'] = request.form.get('category') data['width'] = request.form.get('width') data['depth'] = request.form.get('depth') data['thickness'] = request.form.get('thickness') data['length'] = request.form.get('length') data['amount'] = request.form.get('amount') data['topbar'] = request.form.get('top_bar_type') data['midbar'] = request.form.get('mid_bar_type') data['botbar'] = request.form.get('bot_bar_type') data['stirup'] = request.form.get('stir_bar_type') data['topbar_amt'] = request.form.get('top_bar_amt') data['midbar_amt'] = request.form.get('mid_bar_amt') data['botbar_amt'] = request.form.get('bot_bar_amt') data['stirup_spacing'] = request.form.get('stir_spacing') foundation = Foundation(data['doc_id'], data['tag'], data['wg_tag'], data['width'], data['depth'], data['thickness'], data['length'], data['amount'], data['category'], data['topbar'], data['midbar'], data['botbar'], data['stirup'], data['stirup_spacing'], data['topbar_amt'], data['midbar_amt'], data['botbar_amt']) db.session.add(foundation) db.session.commit() flash('Foundation {} added to project!'.format(data['tag']), 'success') return redirect(url_for('index.getwall'))
def admin_account(id): # Check if admin is logged-in if not admin_loggedin(): return redirect(url_for('login')) page = 'Создать' cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) # Default input account values account = { 'username': '', 'password': '', 'email': '', 'activation_code': '', 'rememberme': '', 'role': 'Member' } roles = ['Member', 'Admin'] # GET request ID exists, edit account if id: # Edit an existing account page = 'Редактировать' # Retrieve account by ID with the GET request ID cursor.execute('SELECT * FROM accounts WHERE id = %s', (id, )) account = cursor.fetchone() if request.method == 'POST' and 'submit' in request.form: # update account password = account['password'] if account['password'] != request.form['password']: hash = request.form['password'] + app.secret_key hash = hashlib.sha1(hash.encode()) password = hash.hexdigest() cursor.execute( 'UPDATE accounts SET username = %s, password = %s, email = %s, activation_code = %s, rememberme = %s, role = %s WHERE id = %s', ( request.form['username'], password, request.form['email'], request.form['activation_code'], request.form['rememberme'], request.form['role'], id, )) mysql.connection.commit() return redirect(url_for('admin')) if request.method == 'POST' and 'delete' in request.form: # delete account cursor.execute('DELETE FROM accounts WHERE id = %s', (id, )) mysql.connection.commit() return redirect(url_for('admin')) if request.method == 'POST' and request.form['submit']: # Create new account hash = request.form['password'] + app.secret_key hash = hashlib.sha1(hash.encode()) password = hash.hexdigest() cursor.execute( 'INSERT INTO accounts (username,password,email,activation_code,rememberme,role) VALUES (%s,%s,%s,%s,%s,%s)', ( request.form['username'], password, request.form['email'], request.form['activation_code'], request.form['rememberme'], request.form['role'], )) mysql.connection.commit() return redirect(url_for('admin')) return render_template('admin/account.html', account=account, page=page, roles=roles)
def decorated_function(*args, **kwargs): if session.get("id") is None or session.get("id") == "": flash("로그인 후 사용 가능한 기능입니다.") return redirect( url_for("member.member_login", next_url=request.url)) return f(*args, **kwargs)
def project_delete(idx): col = mongo.db.version_list_customer col.delete_one({"_id": ObjectId(idx)}) flash("삭제되었습니다.") return redirect(url_for("project.project_write"))
def decorated_fucntion(*args, **kwargs): if session.get("id") is None or session.get("id") == "": return redirect( url_for("member.member_login", next_url=request.url) ) # next_url : 이 데코레이터가 호출된 페이지의 url을 의미 return f(*args, **kwargs)
def decorated_function(*args, **kwargs): if session.get("id") is None or session.get("id") == "": return redirect(url_for("member.member_login", next_url=request.url)) # 현재 페이지 url저장 return f(*args, **kwargs)