Esempio n. 1
0
def share(file_id):  # assuming file_id is given
    file = Files.query.filter_by(id=file_id).first()
    form_data = ShareForm()
    if form_data.validate_on_submit():
        form = dict()
        form['recipient_email'] = []
        form['body'] = form_data.message.data
        form['subject'] = form_data.subject.data
        t1 = form_data.email.data
        t = t1.replace(' ', '')
        form['recipient_email'] = t.split(',')
        for emailid in form['recipient_email']:
            user = User.query.filter_by(email=emailid).first()
            print(type(user))
            if user is not None:
                file.mapping.append(user)
                db.session.commit()

        credentials = google.oauth2.credentials.Credentials(
            **flask.session['credentials'])
        service = build('gmail', 'v1', credentials=credentials)
        sendInst = send_email.send_email(service)
        message = sendInst.create_message_with_attachment(form, file.data)
        print(sendInst.send_message('me', message))
        return redirect(url_for('account'))
    return render_template('share.html',
                           title='SHARE',
                           current_user=current_user,
                           data=getdata(current_user.user_id),
                           form_data=form_data)
Esempio n. 2
0
def share(file_id):  #assuming file_id is given
    file = Files.query.filter_by(id=file_id).first()
    # form = dict()
    # form['recipient_email'] = []
    # form['body'] = request.form['message']
    # form['subject'] = request.form['subject']
    # t = request.form['email'].replace(' ','')
    # form['recipient_email'] = t.split(',')
    # print(form)
    # mail_func(form,file.data)
    form_data = ShareForm()
    if form_data.validate_on_submit():
        form = dict()
        form['recipient_email'] = []
        form['body'] = form_data.message.data
        form['subject'] = form_data.subject.data
        t1 = form_data.email.data
        t = t1.replace(' ', '')
        form['recipient_email'] = t.split(',')
        for emailid in form['recipient_email']:
            user = User.query.filter_by(email=emailid).first()
            print(type(user))
            if user is not None:
                file.mapping.append(user)
                db.session.commit()
        print(form)
        mail_func(form, file.data)
        return redirect(url_for('login'))

    return render_template('share.html',
                           title='SHARE',
                           current_user=current_user,
                           data=getdata(current_user.user_id),
                           form_data=form_data)
Esempio n. 3
0
def add():
    form = ShareForm()
    if form.validate_on_submit():
        ticker = form.ticker.data
        quantity = form.quantity.data
        dividends = form.dividends.data
        bm = Userownedshare(user=current_user.username, quantity=quantity, ticker=ticker, dividends=dividends)
        db.session.add(bm)
        db.session.commit()
        flash("Added share '{}'".format(ticker))
        return redirect(url_for('index'))
    return render_template('add.html', form=form, portfolioids = Userownedshare.listportfolios())
Esempio n. 4
0
def sharesetup(user):
    form = ShareForm()
    if request.form.get('bar', None) == 'Share/Unshare':
    	if form.validate_on_submit():
    	    shareuser = form.shareuser.data
	    if shareuser != user.nickname:
    	    	sharepath = settings.WORKING_DIR + shareuser
	    	shareuserdb = User.query.filter_by(nickname=shareuser).first()
    	    	sharedname = user.nickname + "Repo"
    
    	    	currentRepo = shareuserdb.repos.filter_by(repourl="/" + sharedname + "/").first()
    	    	if currentRepo is None:
	    	    existing = False
    	    	    for sub in os.listdir(sharepath):
	                if sub == sharedname:
	    	    	    existing = True
    	    	    if not existing:
	    	        repo = Repo(settings.REMOTE_DIR + user.nickname)
	    	        os.system("sudo mkdir " + sharepath + "/" + sharedname)
		        working_repo = repo.clone(sharepath + "/" + sharedname , False, False, "origin")
            	        p = subprocess.Popen(["sudo", "git", "remote", "add", "origin", "file:///" + settings.REMOTE_DIR + user.nickname + "/"], cwd=sharepath + "/" + sharedname)
	    	        p.wait()
	    	    newrepo = Rpstry(repourl="/" + sharedname + "/", owner=shareuserdb)
            	    db.session.add(newrepo)
            	    db.session.commit()

	    	    password = ''
	    	    searchfile = open(settings.REMOTE_DIR + shareuser + "/.htpasswd", "r")
	    	    for line in searchfile:
		        exactuser = re.compile("^" + shareuser + ":(.)*$")
                        if exactuser.match(line):
   	            	    password = line
	            searchfile.close()
                    open(settings.REMOTE_DIR + user.nickname + "/.htpasswd", 'a').writelines(password)
                    flash("Shared with: " + shareuser, 'info')
	        else:
	    	    searchfile = open(settings.REMOTE_DIR + user.nickname + "/.htpasswd", "r")
	    	    lines = searchfile.readlines()
	    	    searchfile.close()
	    	    f = open(settings.REMOTE_DIR + user.nickname + "/.htpasswd","w")
	    	    for line in lines:
		        exactuser = re.compile("^" + shareuser + ":(.)*$")
		        if not exactuser.match(line):
		    	    f.write(line)
	            f.close()
	            db.session.delete(currentRepo)
	            db.session.commit()
		    flash("Unshared with: " + shareuser, 'info')
        else:
	    flash("User does not exist", 'error')
    return form
Esempio n. 5
0
def sharewishlist(userid):
    import smtplib
    form = ShareForm()
    form2 = LoginForm()

    if request.method == "POST":
        if form.validate_on_submit() and form2.validate_on_submit():
            from_addr = current_user.email
            to_addr = form.recipientemail.data
            from_name = current_user.first_name + ' ' + current_user.last_name
            to_name = form.name.data
            subject = 'My Wishlist!'
            message = """
            From: {} <{}>
            To: {} <{}>
            Subject: {}

            {}
            """
            # gets item form database
            items = WishlistItem.query.filter_by(
                owner=current_user.get_id()).all()

            message_body = 'This is my wishlist'
            for item in items:
                message_body += "\n-->" + item.title

            message_to_send = message.format(from_name, from_addr, to_name,
                                             to_addr, subject, message_body)
            # Credentials (if needed)
            username = form2.email.data
            password = form2.password.data

            # The actual mail send
            server = smtplib.SMTP('smtp.gmail.com:587')
            server.starttls()
            server.login(username, password)
            server.sendmail(from_addr, to_addr, message_to_send)
            server.quit()

            flash('Wishlist was Shared to ' + to_name, 'success')
        else:
            flash('Invalid sharing data, please try again', 'danger')
        return redirect(url_for("wishlist", userid=current_user.get_id()))
    return redirect(url_for("wishlist", userid=current_user.get_id()))