def upload(): # upload one or more pictures to the filesystem and register it/them in the database if not 'MyWebsite_user_id' in session.keys(): return redirect('/') if not User.is_logged_in(session['MyWebsite_user_id'],session['login_session']): return redirect('/danger') user=User.get_one(session['MyWebsite_user_id']) album_id=request.form['active_album'] # f=request.files['new_pic'] files=request.files.getlist('new_pic') for eachfile in files: filename=secure_filename(eachfile.filename) ALLOWED_EXTENSIONS = ('bmp','png', 'jpg', 'jpeg', 'gif') if '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS: print(filename) if path.exists('UserFiles/'+user.email+'/'+filename): # Album.add_pic(user,pic,album_id) filename=filename.rsplit('.',1) filename[0]=filename[0]+str(round(datetime.timestamp(datetime.now()))) filename='.'.join(filename) # Save pic to the filesystem eachfile.save('UserFiles/'+user.email+'/'+filename) # Add pic to the pictures db pic=Picture.new(user.id,user.email+'/'+filename,filename) # Add pic to the active album Album.add_pic(user,pic,album_id) # Create thumbnail image using PIL im=Image.open('UserFiles/'+user.email+'/'+filename) im.thumbnail((100,100),Image.ANTIALIAS) im.save('UserFiles/thumbnails/'+user.email+'/'+filename) user.set_active_album(album_id) else: print('invalid file extension.') return redirect('/dashboard')
def update_profile(): if not 'MyWebsite_user_id' in session.keys(): return redirect('/') if not User.is_logged_in(session['MyWebsite_user_id'],session['login_session']): return redirect('/danger') # need email validations user=User.get_one(session['MyWebsite_user_id']) if user.email!=request.form['email_address']: user.update_email(request.form['email_address']) f=request.files['profile_pic'] filename=secure_filename(f.filename) ALLOWED_EXTENSIONS = ('bmp','png', 'jpg', 'jpeg', 'gif') if '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS: # Save pic to the filesystem f.save('UserFiles/'+user.email+'/'+filename) # Add pic to the pictures db pic=Picture.new(user.id,user.email+'/'+filename,filename) # set user's picture to what they just uploaded. user.update_profile_pic(pic.id) return redirect ('/dashboard')