Spaces:
Sleeping
Sleeping
Upload server.py
Browse files
server.py
CHANGED
|
@@ -198,40 +198,58 @@ def static_files(filename: str) -> Any:
|
|
| 198 |
|
| 199 |
|
| 200 |
@app.route("/api/register", methods=["POST"])
|
| 201 |
-
def api_register() -> Any:
|
| 202 |
-
payload = request.get_json(force=True)
|
| 203 |
-
email = payload.get("email")
|
| 204 |
-
password = payload.get("password")
|
| 205 |
-
confirm = payload.get("confirm_password")
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
login_key, display_email = normalize_email(email)
|
| 213 |
password_hash = hash_password(password)
|
| 214 |
|
| 215 |
-
if DATABASE_AVAILABLE:
|
| 216 |
-
if fetch_one("SELECT 1 FROM accounts WHERE login = %s", (login_key,)):
|
| 217 |
-
return jsonify({"error": "Konto o podanym emailu juz istnieje."}), 400
|
| 218 |
-
create_account(login_key, display_email, password_hash)
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
"
|
| 229 |
-
"
|
| 230 |
-
"
|
| 231 |
-
"
|
| 232 |
-
"
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
| 235 |
return jsonify({"message": "Konto zostalo utworzone."})
|
| 236 |
|
| 237 |
|
|
|
|
| 198 |
|
| 199 |
|
| 200 |
@app.route("/api/register", methods=["POST"])
|
| 201 |
+
def api_register() -> Any:
|
| 202 |
+
payload = request.get_json(force=True)
|
| 203 |
+
email = payload.get("email")
|
| 204 |
+
password = payload.get("password")
|
| 205 |
+
confirm = payload.get("confirm_password")
|
| 206 |
+
business_fields = [
|
| 207 |
+
"company_name",
|
| 208 |
+
"owner_name",
|
| 209 |
+
"address_line",
|
| 210 |
+
"postal_code",
|
| 211 |
+
"city",
|
| 212 |
+
"tax_id",
|
| 213 |
+
"bank_account",
|
| 214 |
+
]
|
| 215 |
+
business_data: Dict[str, str] = {}
|
| 216 |
+
|
| 217 |
+
for field in business_fields:
|
| 218 |
+
value = (payload.get(field) or "").strip()
|
| 219 |
+
if not value:
|
| 220 |
+
return jsonify({"error": f"Pole {field} jest wymagane."}), 400
|
| 221 |
+
business_data[field] = value
|
| 222 |
+
|
| 223 |
+
if password != confirm:
|
| 224 |
+
return jsonify({"error": "Hasla musza byc identyczne."}), 400
|
| 225 |
+
if len(password or "") < PASSWORD_MIN_LENGTH:
|
| 226 |
+
return jsonify({"error": "Haslo jest za krotkie."}), 400
|
| 227 |
|
| 228 |
login_key, display_email = normalize_email(email)
|
| 229 |
password_hash = hash_password(password)
|
| 230 |
|
| 231 |
+
if DATABASE_AVAILABLE:
|
| 232 |
+
if fetch_one("SELECT 1 FROM accounts WHERE login = %s", (login_key,)):
|
| 233 |
+
return jsonify({"error": "Konto o podanym emailu juz istnieje."}), 400
|
| 234 |
+
account_id = create_account(login_key, display_email, password_hash)
|
| 235 |
+
update_business(account_id, business_data)
|
| 236 |
+
return jsonify({"message": "Konto zostalo utworzone."})
|
| 237 |
+
|
| 238 |
+
data = load_store()
|
| 239 |
+
accounts = data.setdefault("accounts", {})
|
| 240 |
+
if login_key in accounts:
|
| 241 |
+
return jsonify({"error": "Konto o podanym emailu juz istnieje."}), 400
|
| 242 |
+
|
| 243 |
+
accounts[login_key] = {
|
| 244 |
+
"login": login_key,
|
| 245 |
+
"email": display_email,
|
| 246 |
+
"password_hash": password_hash,
|
| 247 |
+
"business": business_data,
|
| 248 |
+
"invoices": [],
|
| 249 |
+
"logo": None,
|
| 250 |
+
"created_at": datetime.utcnow().isoformat(timespec="seconds"),
|
| 251 |
+
}
|
| 252 |
+
save_store(data)
|
| 253 |
return jsonify({"message": "Konto zostalo utworzone."})
|
| 254 |
|
| 255 |
|