-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
656 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
VITE_API_BASE_URL=REPLACE_ME | ||
VITE_API_BASE_URL=http://localhost:8000/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// TODO: rename this file to session.ts and move to codeforlife-sso-frontend. | ||
|
||
import { type Class, type OtpBypassToken, type User } from "codeforlife/api" | ||
import { type SessionMetadata } from "codeforlife/hooks" | ||
import { type Arg } from "codeforlife/utils/api" | ||
|
||
import api from "." | ||
|
||
const baseUrl = "sso/session/" | ||
|
||
const ssoApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
loginWithEmail: build.mutation< | ||
SessionMetadata, | ||
Arg<User, "email" | "password"> | ||
>({ | ||
query: body => ({ | ||
url: baseUrl + "login-with-email/", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
loginWithOtp: build.mutation<null, { otp: number }>({ | ||
query: body => ({ | ||
url: baseUrl + "otp/", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
loginWithOtpBypassToken: build.mutation< | ||
SessionMetadata, | ||
Arg<OtpBypassToken, "token"> | ||
>({ | ||
query: body => ({ | ||
url: baseUrl + "login-with-otp-bypass-token/", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
loginAsStudent: build.mutation< | ||
SessionMetadata, | ||
Arg<User, "first_name" | "password"> & { class_id: Class["id"] } | ||
>({ | ||
query: body => ({ | ||
url: baseUrl + "login-as-student/", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
autoLoginAsStudent: build.mutation< | ||
SessionMetadata, | ||
{ | ||
user_id: User["id"] | ||
auto_gen_password: string | ||
} | ||
>({ | ||
query: body => ({ | ||
url: baseUrl + "auto-login-as-student/", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
}), | ||
}) | ||
|
||
export default ssoApi | ||
export const { | ||
useLoginWithEmailMutation, | ||
useLoginWithOtpMutation, | ||
useLoginWithOtpBypassTokenMutation, | ||
useLoginAsStudentMutation, | ||
useAutoLoginAsStudentMutation, | ||
} = ssoApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as yup from "yup" | ||
|
||
export const accessCodeSchema = yup | ||
.string() | ||
.matches(/^[A-Z0-9]{5}$/, "Invalid access code") | ||
|
||
const passwordSchema = yup.string().required("required") | ||
|
||
export const teacherPasswordSchema = passwordSchema.test({ | ||
message: "too-weak", | ||
test: password => | ||
password.length >= 10 && | ||
!( | ||
password.search(/[A-Z]/) === -1 || | ||
password.search(/[a-z]/) === -1 || | ||
password.search(/[0-9]/) === -1 || | ||
password.search(/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/) === -1 | ||
), | ||
}) | ||
|
||
export const studentPasswordSchema = passwordSchema.test({ | ||
message: "too-weak", | ||
test: password => password.length >= 6, | ||
}) | ||
|
||
// TODO: make indy password schema the same as teacher's. | ||
export const indyPasswordSchema = passwordSchema.test({ | ||
message: "too-weak", | ||
test: password => | ||
password.length >= 8 && | ||
!( | ||
password.search(/[A-Z]/) === -1 || | ||
password.search(/[a-z]/) === -1 || | ||
password.search(/[0-9]/) === -1 | ||
), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.