diff --git a/client/pages/login.tsx b/client/pages/login.tsx index 2323fb891..ca91730bc 100644 --- a/client/pages/login.tsx +++ b/client/pages/login.tsx @@ -34,7 +34,7 @@ const LoginPage = () => { const { isAuthenticated } = useStoreState((s) => s.auth); const login = useStoreActions((s) => s.auth.login); const [error, setError] = useState(""); - const [verifying, setVerifying] = useState(false); + const [message, setMessage] = useState(""); const [loading, setLoading] = useState({ login: false, signup: false }); const [formState, { email, password, label }] = useFormState<{ email: string; @@ -79,8 +79,8 @@ const LoginPage = () => { if (type === "signup" && !DISALLOW_REGISTRATION) { setLoading((s) => ({ ...s, signup: true })); try { - await axios.post(APIv2.AuthSignup, { email, password }); - setVerifying(true); + const res = await axios.post(APIv2.AuthSignup, { email, password }); + setMessage(res.data.message); } catch (error) { setError(error.response.data.error); } @@ -97,10 +97,9 @@ const LoginPage = () => { return ( - {verifying ? ( + {message ? (

- A verification email has been sent to{" "} - {formState.values.email}. + {message}

) : ( diff --git a/knexfile.ts b/knexfile.ts index 7e8a05f2f..4fce07ff0 100644 --- a/knexfile.ts +++ b/knexfile.ts @@ -9,7 +9,7 @@ module.exports = { user: env.DB_USER, port: env.DB_PORT, password: env.DB_PASSWORD, - ssl: env.DB_SSL, + ssl: env.DB_SSL === true ? { "rejectUnauthorized": false } : false, }, migrations: { tableName: "knex_migrations", diff --git a/server/handlers/auth.ts b/server/handlers/auth.ts index 7c9b25496..2f0f4e448 100644 --- a/server/handlers/auth.ts +++ b/server/handlers/auth.ts @@ -120,9 +120,16 @@ export const signup: Handler = async (req, res) => { req.user ); + if (!process.env.MAIL_HOST) { + return res + .status(201) + .send({ message: "Your account has been created successfully." }); + } await mail.verification(user); - return res.status(201).send({ message: "Verification email has been sent." }); + return res + .status(201) + .send({ message: `Verification email has been sent to ${user.email}.` }); }; export const token: Handler = async (req, res) => { diff --git a/server/handlers/links.ts b/server/handlers/links.ts index 5134cd0d1..2ba99719a 100644 --- a/server/handlers/links.ts +++ b/server/handlers/links.ts @@ -289,18 +289,37 @@ export const redirect = (app: ReturnType): Handler => async ( return res.redirect("/banned"); } - // 5. If wants to see link info, then redirect + // 5. Append query string when provided + if (req.query) { + const url = URL.parse(link.target, true); + const linkTargetParams = new URLSearchParams(url.search); + + let added = 0; + Object.entries(req.query).forEach(([key, value]) => { + if (typeof value === "string") { + added++; + linkTargetParams.append(key, value); + } + }); + + if (added) { + url.search = linkTargetParams.toString(); + link.target = URL.format(url); + } + } + + // 6. If wants to see link info, then redirect const doesRequestInfo = /.*\+$/gi.test(req.params.id); if (doesRequestInfo && !link.password) { return app.render(req, res, "/url-info", { target: link.target }); } - // 6. If link is protected, redirect to password page + // 7. If link is protected, redirect to password page if (link.password) { return res.redirect(`/protected/${link.uuid}`); } - // 7. Create link visit + // 8. Create link visit if (link.user_id && !isBot) { queue.visit.add({ headers: req.headers, @@ -310,7 +329,19 @@ export const redirect = (app: ReturnType): Handler => async ( }); } - // 8. Redirect to target + // 9. Create Google Analytics visit + if (env.GOOGLE_ANALYTICS_UNIVERSAL && !isBot) { + ua(env.GOOGLE_ANALYTICS_UNIVERSAL) + .pageview({ + dp: `/${address}`, + ua: req.headers["user-agent"], + uip: req.realIP, + aip: 1 + }) + .send(); + } + + // 10. Redirect to target return res.redirect(link.target); }; diff --git a/server/handlers/validators.ts b/server/handlers/validators.ts index 895402122..7180bbd48 100644 --- a/server/handlers/validators.ts +++ b/server/handlers/validators.ts @@ -52,7 +52,7 @@ export const createLink = [ .custom( value => urlRegex({ exact: true, strict: false }).test(value) || - /^(?!https?)(\w+):\/\//.test(value) + /^(?!https?)(\w[\w-]+):\/\//.test(value) ) .withMessage("URL is not valid.") .custom(value => removeWww(URL.parse(value).host) !== env.DEFAULT_DOMAIN) @@ -140,7 +140,7 @@ export const editLink = [ .custom( value => urlRegex({ exact: true, strict: false }).test(value) || - /^(?!https?)(\w+):\/\//.test(value) + /^(?!https?)(\w[\w-]+):\/\//.test(value) ) .withMessage("URL is not valid.") .custom(value => removeWww(URL.parse(value).host) !== env.DEFAULT_DOMAIN) diff --git a/server/queries/user.ts b/server/queries/user.ts index 12d84a3be..742556b77 100644 --- a/server/queries/user.ts +++ b/server/queries/user.ts @@ -36,7 +36,8 @@ export const add = async (params: Add, user?: User) => { email: params.email, password: params.password, verification_token: uuid(), - verification_expires: addMinutes(new Date(), 60).toISOString() + verification_expires: addMinutes(new Date(), 60).toISOString(), + verified: process.env.MAIL_HOST ? false : true }; if (user) { diff --git a/server/utils/index.ts b/server/utils/index.ts index cda1956b5..1b8580430 100644 --- a/server/utils/index.ts +++ b/server/utils/index.ts @@ -51,7 +51,7 @@ export const generateId = async (domain_id: number = null) => { }; export const addProtocol = (url: string): string => { - const hasProtocol = /^\w+:\/\//.test(url); + const hasProtocol = /^\w[\w-]+:\/\//.test(url); return hasProtocol ? url : `http://${url}`; };