Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Activate workflow

Tianzhou Chen91c31cd59b2f
diff --git a/frontend/src/miragejs/factories/activateInfo.js b/frontend/src/miragejs/factories/activateInfo.js
new file mode 100644
index 0000000000..b232919f2e
--- /dev/null
+++ b/frontend/src/miragejs/factories/activateInfo.js
@@ -0,0 +1,18 @@
+import { Factory } from "miragejs";
+
+export default {
+ activateInfo: Factory.extend({
+ email() {
+ return "[email protected]";
+ },
+ password() {
+ return "blablabla";
+ },
+ name() {
+ return "foo";
+ },
+ token() {
+ return "12345";
+ },
+ }),
+};
diff --git a/frontend/src/miragejs/factories/index.js b/frontend/src/miragejs/factories/index.js
index 642b7188c8..4f38727c3c 100644
--- a/frontend/src/miragejs/factories/index.js
+++ b/frontend/src/miragejs/factories/index.js
@@ -13,6 +13,7 @@ import roleMapping from "./roleMapping";
import batchUpdate from "./batchUpdate";
import loginInfo from "./loginInfo";
import signupInfo from "./signupInfo";
+import activateInfo from "./activateInfo";
/*
* factories are contained in a single object, that's why we
@@ -35,4 +36,5 @@ export default {
...batchUpdate,
...loginInfo,
...signupInfo,
+ ...activateInfo,
};
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index aab508e1d1..bd73da35c5 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -60,4 +60,6 @@ export default {
signupInfo: Model,
loginInfo: Model,
+
+ activateInfo: Model,
};
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 01729213a9..628ff566ec 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -76,6 +76,31 @@ export default function routes() {
return createdUser;
});
+ this.post("/auth/activate", function (schema, request) {
+ const activateInfo = this.normalizedRequestAttrs("activate-info");
+ if (!activateInfo.token) {
+ return new Response(400, {}, { errors: "Missing activation token" });
+ }
+
+ const user = schema.users.findBy({ email: activateInfo.email });
+ if (user) {
+ const ts = Date.now();
+ user.update({
+ name: activateInfo.name,
+ status: "ACTIVE",
+ lastUpdatedTs: ts,
+ passwordHash: activateInfo.password,
+ });
+ return user;
+ }
+
+ return new Response(
+ 400,
+ {},
+ { errors: activateInfo.email + " is not invited" }
+ );
+ });
+
// RoleMapping
this.get("/rolemapping", function (schema, request) {
return schema.roleMappings.where((roleMapping) => {
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index fda3fdea1f..81224629b7 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -12,6 +12,7 @@ import DashboardSidebar from "../views/DashboardSidebar.vue";
import Home from "../views/Home.vue";
import Signin from "../views/auth/Signin.vue";
import Signup from "../views/auth/Signup.vue";
+import Activate from "../views/auth/Activate.vue";
import PasswordReset from "../views/auth/PasswordReset.vue";
import { store } from "../store";
import { idFromSlug } from "../utils";
@@ -20,6 +21,7 @@ const HOME_MODULE = "workspace.home";
const AUTH_MODULE = "auth";
const SIGNIN_MODULE = "auth.signin";
const SIGNUP_MODULE = "auth.signup";
+const ACTIVATE_MODULE = "auth.activate";
const PASSWORD_RESET_MODULE = "auth.password.reset";
const routes: Array<RouteRecordRaw> = [
@@ -43,6 +45,13 @@ const routes: Array<RouteRecordRaw> = [
component: Signup,
props: true,
},
+ {
+ path: "activate",
+ name: ACTIVATE_MODULE,
+ meta: { title: () => "Activate" },
+ component: Activate,
+ props: true,
+ },
{
path: "password-reset",
name: PASSWORD_RESET_MODULE,
@@ -305,12 +314,24 @@ router.beforeEach((to, from, next) => {
if (
to.name === SIGNIN_MODULE ||
to.name === SIGNUP_MODULE ||
+ to.name === ACTIVATE_MODULE ||
to.name === PASSWORD_RESET_MODULE
) {
if (loginUser) {
next({ name: HOME_MODULE, replace: true });
} else {
- next();
+ if (to.name === ACTIVATE_MODULE) {
+ const token = to.query.token;
+ if (token) {
+ // TODO: Needs to validate the token
+ next();
+ } else {
+ // Go to signup if token is missing
+ next({ name: SIGNUP_MODULE, replace: true });
+ }
+ } else {
+ next();
+ }
}
return;
} else {
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
index 7ade9f1a54..dffe3e9e43 100644
--- a/frontend/src/store/modules/auth.ts
+++ b/frontend/src/store/modules/auth.ts
@@ -4,6 +4,7 @@ import {
AuthState,
LoginInfo,
SignupInfo,
+ ActivateInfo,
ResourceObject,
} from "../../types";
@@ -60,6 +61,20 @@ const actions = {
return newUser;
},
+ async activate({ commit }: any, activateInfo: ActivateInfo) {
+ const activatedUser = convert(
+ (
+ await axios.post("/api/auth/activate", {
+ data: { type: "activateInfo", attributes: activateInfo },
+ })
+ ).data.data
+ );
+
+ localStorage.setItem("bb.auth.user", JSON.stringify(activatedUser));
+ commit("setCurrentUser", activatedUser);
+ return activatedUser;
+ },
+
async fetchCurrentUser({ commit }: any) {
const currentUser = convert((await axios.get("/api/user/1")).data.data);
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index eec94341ba..917932acad 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -251,6 +251,13 @@ export type SignupInfo = {
name: string;
};
+export type ActivateInfo = {
+ email: string;
+ password: string;
+ name: string;
+ token: string;
+};
+
// UI State Models
export type RouterSlug = {
taskSlug?: string;
diff --git a/frontend/src/views/auth/Activate.vue b/frontend/src/views/auth/Activate.vue
new file mode 100644
index 0000000000..514ba45f68
--- /dev/null
+++ b/frontend/src/views/auth/Activate.vue
@@ -0,0 +1,133 @@
+<template>
+ <div class="mx-auto w-full max-w-sm">
+ <div>
+ <img class="h-12 w-auto" src="../../assets/logo.svg" alt="Bytebase" />
+ <h2 class="mt-6 text-3xl leading-9 font-extrabold text-main">
+ Activate your
+ <span class="text-accent font-semnibold">{{
+ state.role.charAt(0).toUpperCase() + state.role.slice(1).toLowerCase()
+ }}</span>
+ account
+ </h2>
+ </div>
+
+ <div class="mt-8">
+ <div class="mt-6">
+ <form @submit.prevent="tryActivate" class="space-y-6">
+ <div>
+ <label
+ for="email"
+ class="block text-sm font-medium leading-5 text-control"
+ >
+ Email
+ </label>
+ <div class="mt-2 text-base font-medium leading-5 text-accent">
+ {{ state.email }}
+ </div>
+ </div>
+ <div>
+ <label
+ for="password"
+ class="block text-sm font-medium leading-5 text-control"
+ >
+ Password<span class="text-red-600">*</span>
+ </label>
+ <div class="mt-1 rounded-md shadow-sm">
+ <input
+ id="password"
+ type="password"
+ autocomplete="on"
+ v-model="state.password"
+ required
+ class="appearance-none block w-full px-3 py-2 border border-control-border rounded-md placeholder-control-placeholder focus:outline-none focus:shadow-outline-blue focus:border-control-border sm:text-sm sm:leading-5"
+ />
+ </div>
+ </div>
+
+ <div>
+ <label
+ for="email"
+ class="block text-sm font-medium leading-5 text-control"
+ >
+ Name
+ </label>
+ <div class="mt-1 rounded-md shadow-sm">
+ <input
+ id="name"
+ type="text"
+ v-model="state.name"
+ placeholder="Jim Gray"
+ class="appearance-none block w-full px-3 py-2 border border-control-border rounded-md placeholder-control-placeholder focus:outline-none focus:shadow-outline-blue focus:border-control-border sm:text-sm sm:leading-5"
+ />
+ </div>
+ </div>
+
+ <div>
+ <span class="block w-full rounded-md shadow-sm">
+ <button
+ type="submit"
+ class="btn-success w-full flex justify-center py-2 px-4"
+ >
+ Activate
+ </button>
+ </span>
+ </div>
+ </form>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { reactive } from "vue";
+import { useStore } from "vuex";
+import { useRouter } from "vue-router";
+import { ActivateInfo, RoleType } from "../../types";
+
+interface LocalState {
+ email: string;
+ password: string;
+ name: string;
+ role: RoleType;
+}
+
+export default {
+ name: "Activate",
+ setup(props, ctx) {
+ const store = useStore();
+ const router = useRouter();
+ const token = router.currentRoute.value.query.token as string;
+
+ // TODO: Get info from token
+ const state = reactive<LocalState>({
+ email: "[email protected]",
+ password: "",
+ name: "Bob Invited",
+ role: "DEVELOPER",
+ });
+
+ const tryActivate = () => {
+ const activateInfo: ActivateInfo = {
+ email: state.email,
+ password: state.password,
+ name: state.name,
+ token: token,
+ };
+ store
+ .dispatch("auth/activate", activateInfo)
+ .then(() => {
+ router.push("/");
+ })
+ .catch((error: Error) => {
+ console.log(error);
+ return;
+ });
+ };
+
+ return {
+ state,
+ tryActivate,
+ };
+ },
+};
+</script>