def register(): form = RegistrationForm() if request.method == 'POST': if form.validate_on_submit(): try: theanonid = random_user_name_anon() now = datetime.utcnow() cryptedpwd = User.cryptpassword(password=form.password.data) # add user to db newuser = User(user_name=form.user_name.data, email=form.email.data, password_hash=cryptedpwd, wallet_pin='0', profileimage='', bannerimage='', member_since=now, admin=0, admin_role=0, bio='', last_seen=now, locked=0, fails=0, confirmed=0, anon_id=theanonid, anon_mode=0, over_age=0, agree_to_tos=True, banned=0, color_theme=3, post_style=1) db.session.add(newuser) db.session.commit() # profile info userbio = UserPublicInfo(user_id=newuser.id, bio='', short_bio='') stats_for_bch = UserStatsBCH( user_name=newuser.user_name, user_id=newuser.id, # given to posters/commenters total_donated_to_postcomments_bch=0, total_donated_to_postcomments_usd=0, # recieved from posting total_recievedfromposts_bch=0, total_recievedfromposts_usd=0, # recieved from comments total_recievedfromcomments_bch=0, total_recievedfromcomments_usd=0, # given to charities total_donated_to_cause_bch=0, total_donated_to_cause_usd=0, ) stats_for_user = UserStats(user_name=newuser.user_name, user_id=newuser.id, post_upvotes=0, post_downvotes=0, comment_upvotes=0, comment_downvotes=0, total_posts=0, total_comments=0, user_level=1, user_exp=0, user_width_next_level='0') users_timers = UserTimers(user_name=newuser.user_name, user_id=newuser.id, account_created=now, last_post=now, last_common_creation=now, last_comment=now, last_report=now) # add to db db.session.add(userbio) db.session.add(users_timers) db.session.add(stats_for_user) db.session.add(stats_for_bch) # commit db.session.commit() # make a user a directory getusernodelocation = userimagelocation(x=newuser.id) userfolderlocation = os.path.join(UPLOADED_FILES_DEST, current_disk, 'user', getusernodelocation, str(newuser.id)) mkdir_p(path=userfolderlocation) # login new user try: # bitcoin cash bch_create_wallet(user_id=newuser.id) except: pass login_user(newuser) current_user.is_authenticated() current_user.is_active() flash( "Successfully Registered." " If you want to access your wallet," " you will need to confirm your email. If you used an invalid email," " you can change this in account settings.", category="success") return redirect(url_for('welcome')) except Exception as e: return redirect((request.args.get('next', request.referrer))) else: for errors in form.user_name.errors: flash(errors, category="danger") for errors in form.password.errors: flash(errors, category="danger") for errors in form.passwordtwo.errors: flash(errors, category="danger") for errors in form.passwordtwo.errors: flash(errors, category="danger") return redirect((request.args.get('next', request.referrer))) return render_template('users/register.html', form=form)
def profilepicture(): id_pic1 = id_generator_picture1() form = ProfilePicForm(CombinedMultiDict((request.files, request.form)), ) user = User.query.filter_by(id=current_user.id).first() if request.method == 'POST': if form.delete.data and form.validate_on_submit(): deleteuserprofileimage(user_id=user.id) return redirect((request.args.get('next', request.referrer))) if form.submit.data and form.validate_on_submit(): getusernodelocation = userimagelocation(x=user.id) userlocation = os.path.join(UPLOADED_FILES_DEST, current_disk, 'user', getusernodelocation, str(user.id)) if form.imageprofile.data: try: mkdir_p(path=userlocation) deleteuserprofileimage(user_id=current_user.id) filename = secure_filename(form.imageprofile.data.filename) # makes directory (generic location + auction number id as folder) # saves it to location profileimagefilepath = os.path.join(userlocation, filename) form.imageprofile.data.save(profileimagefilepath) # RENAMING FILE # split file name and ending filenamenew, file_extension = os.path.splitext( profileimagefilepath) # gets new 64 digit filename newfilename = id_pic1 + file_extension # puts new name with ending filenamenewfull = filenamenew + file_extension # gets aboslute path of new file newfilenamedestination = os.path.join( userlocation, newfilename) # renames file os.rename(filenamenewfull, newfilenamedestination) convert_profile_image(imagelocation=userlocation, imagename=newfilename) except Exception as e: user.profileimage = "0" flash("Error", category="success") return redirect((request.args.get('next', request.referrer))) if not form.imageprofile.data.filename: user.profileimage = "" db.session.add(user) db.session.commit() flash("Profile has been changed", category="success") return redirect((request.args.get('next', request.referrer))) else: flash("Error. No data submitted", category="danger") return redirect((request.args.get('next', request.referrer))) return render_template( 'users/profile/profile_forms/profile_picture.html', form=form, user=user, )
def bannerpicture(business_id): id_pic1 = id_generator_picture1() form = BannerPicForm( CombinedMultiDict((request.files, request.form)), ) thebiz = db.session.query(Business).filter(Business.id == business_id).first() if current_user.id != thebiz.user_id: return redirect(url_for('index')) if request.method == 'POST': if current_user.id != thebiz.user_id: return redirect(url_for('index')) if form.delete.data and form.validate_on_submit(): deletebannerimage(business_id=thebiz.id) return redirect((request.args.get('next', request.referrer))) if form.submit.data and form.validate_on_submit(): getusernodelocation = userimagelocation(x=thebiz.id) userlocation = os.path.join(UPLOADED_FILES_DEST, current_disk, 'business', getusernodelocation, str(thebiz.id)) if form.imageprofile.data: try: # make a user a directory mkdir_p(path=userlocation) deletebannerimage(business_id=thebiz.id) filename = secure_filename(form.imageprofile.data.filename) # makes directory (generic location + auction number id as folder) profileimagefilepath = os.path.join(userlocation, filename) # saves it to location form.imageprofile.data.save(profileimagefilepath) # RENAMING FILE # split file name and ending filenamenew, file_extension = os.path.splitext(profileimagefilepath) # gets new 64 digit filename newfilename = id_pic1 + file_extension # puts new name with ending filenamenewfull = filenamenew + file_extension # gets aboslute path of new file newfilenamedestination = os.path.join(userlocation, newfilename) # renames file os.rename(filenamenewfull, newfilenamedestination) convert_banner_image(imagelocation=userlocation, imagename=newfilename, business_id=thebiz.id) except Exception as e: thebiz.bannerimage = "" flash("Error", category="success") return redirect((request.args.get('next', request.referrer))) if not form.imageprofile.data.filename: thebiz.bannerimage = '' db.session.add(thebiz) db.session.commit() flash("Profile banner has been changed", category="success") return redirect((request.args.get('next', request.referrer))) else: flash("Error. No data submitted", category="danger") return redirect((request.args.get('next', request.referrer))) return render_template('business/edit/images/profile_banner.html', form=form, thebiz=thebiz, )