def wrapper(*args, **kwargs): for f in exists: if not os.path.exists(get_path(f)): return render_error("%s is not exists" % get_abs_path(get_path(f))) for f in not_exists: if os.path.exists(get_path(f)): return render_error("%s is exists" % get_abs_path(get_path(f))) for f in is_file: if not os.path.isfile(get_path(f)): return render_error("%s is not a file" % get_abs_path(get_path(f))) for f in is_dir: if not os.path.isdir(get_path(f)): return render_error("%s is not a directory" % get_abs_path(get_path(f))) return func(*args, **kwargs)
def active(): uid = request.args.get("uid") code = request.args.get("code") u = User.find_by_id(int(uid)) if not u: return render_error("Account not exists.") if code == u.code: u.enable = True u.save() if u.enable: session["email"] = u.username session["current_user"] = u.__dict__ session["root"] = SYS_ROOT + "/" + u.username + "/" if not os.path.isdir(session["root"]): os.mkdir(session["root"]) return redirect("") return render_error("Active Failed!")
def rm(): if get_abs_path(get_path()) in BASE_FILE: return render_error("%s cannot be removed." % (get_abs_path(get_path()),)) if os.path.isdir(get_path()): os.removedirs(get_path()) elif os.path.isfile(get_path()): os.remove(get_path()) else: os.remove(get_path()) return jsonify(**file_2_info(get_path()))
def login(): u = User.login(request.form.get("email"), request.form.get("password")) if u is not None: session["email"] = request.form.get("email") session["current_user"] = User.find_by_email(session["email"]).__dict__ session["current_user"]["username"] = session["email"] session["root"] = SYS_ROOT + "/" + u.username + "/" if not os.path.isdir(session["root"]): os.mkdir(session["root"]) return jsonify(**{"user": u.__dict__}) else: return render_error("Login Error")
def cp(): abs_parent_dir = (session["root"] + get_parent_abs_path(get_path("dest"))).replace("//", "/") if os.path.isfile(abs_parent_dir[: (len(abs_parent_dir) - 1)]): return render_error("%s is a file" % get_abs_path(abs_parent_dir)) if not os.path.isdir(abs_parent_dir): os.mkdir(abs_parent_dir) if os.path.isdir(get_path("source")): shutil.copytree(get_path("source"), get_path("dest")) else: shutil.copyfile(get_path("source"), get_path("dest")) return jsonify(**{"source": file_2_info(get_path("source")), "dest": file_2_info(get_path("dest"))})
def register(): if session.get("current_user"): return render_error("You have registered.") import smtplib email = request.form.get("email") password = request.form.get("password") u = User.find_one(username=email) if u: return render_error("You has already registered.") u = User(email=email, username=email, password=User.encrypt(password), code=User.encrypt("%s code %s" % (email, password))).save() if hasattr(u, u.Meta.primary): session["current_user"] = u.__dict__ sender = "*****@*****.**" recivers = [email, ] smtp_obj = smtplib.SMTP("smtp.abillist.com", 25) smtp_obj.login(sender, "1008_not") subject = "Account Active Mail" html = """ Click <a href='http://%s/user/active?uid=%s&code=%s'>http://%s/user/active?uid=%s&code=%s</a> to active your account. <br> Your password: %s """ % ("sys.abillist.com", str(u.m_id), u.code, "sys.abillist.com", str(u.m_id), u.code, password) message = "\r\n".join([ "From: " + sender, "MIME-Version: 1.0", "Content-type: text/html", "Subject: " + subject, "\r\n", html ]) smtp_obj.sendmail(sender, recivers, message) return jsonify(**{"user": u.__dict__}) else: return render_error("Register Error.")
def mv(): if get_abs_path(get_path("source")) in BASE_FILE: return render_error("%s cannot be removed." % (get_abs_path(get_path()),)) shutil.move(get_path("source"), get_path("dest")) return jsonify(**{"source": file_2_info(get_path("source")), "dest": file_2_info(get_path("dest"))})
def decorated_function(*args, **kwargs): if session.get("current_user") is None or not session.get("current_user")["enable"]: return render_error("login required.") return f(*args, **kwargs)