Feature/Auth: implement user authentication #3
@@ -45,7 +45,7 @@ public class AuthController : ControllerBase {
|
|||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
public async Task<ActionResult> Login(LoginDto dto)
|
public async Task<ActionResult> Login(LoginDto dto)
|
||||||
{
|
{
|
||||||
var user = await users_.Get(dto.UserName);
|
var user = await userManager_.FindByNameAsync(dto.UserName);
|
||||||
|
|
||||||
if (user == null) return Unauthorized();
|
if (user == null) return Unauthorized();
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ onMounted(() => { // register callback for when component is loaded on page
|
|||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr v-for="user in store.users" :key="user.id">
|
<tr v-for="user in store.users" :key="user.id">
|
||||||
<td>{{ user.name }}</td>
|
<td>{{ user.username }}</td>
|
||||||
<td>
|
<td>
|
||||||
<router-link :to="`/user/${user.id}`">Edit</router-link>
|
<router-link :to="`/user/${user.id}`">Edit</router-link>
|
||||||
<button @click="store.removeUser(user.id)">Delete</button>
|
<button @click="store.removeUser(user.id)">Delete</button>
|
||||||
|
|||||||
@@ -4,18 +4,18 @@
|
|||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
username: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RegisterDto {
|
export interface RegisterDto {
|
||||||
name: string;
|
username: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginDto {
|
export interface LoginDto {
|
||||||
name: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import * as authApi from "../api/AuthApi";
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const user = reactive<LoginDto>({ // the template ensures type consistency
|
const user = reactive<LoginDto>({ // the template ensures type consistency
|
||||||
name: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ async function login(): Promise<void> {
|
|||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
|
|
||||||
<form @submit.prevent="login">
|
<form @submit.prevent="login">
|
||||||
<input v-model="user.name" placeholder="username" />
|
<input v-model="user.username" placeholder="username" />
|
||||||
<input v-model="user.password" type="password" placeholder="password" />
|
<input v-model="user.password" type="password" placeholder="password" />
|
||||||
|
|
||||||
<button type="submit">Submit</button>
|
<button type="submit">Submit</button>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import * as authApi from "../api/AuthApi";
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const user = reactive<RegisterDto>({ // the template ensures type consistency
|
const user = reactive<RegisterDto>({ // the template ensures type consistency
|
||||||
name: "",
|
username: "",
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
});
|
});
|
||||||
@@ -40,7 +40,7 @@ async function register(): Promise<void> {
|
|||||||
<h2>Register</h2>
|
<h2>Register</h2>
|
||||||
|
|
||||||
<form @submit.prevent="register">
|
<form @submit.prevent="register">
|
||||||
<input v-model="user.name" placeholder="username" />
|
<input v-model="user.username" placeholder="username" />
|
||||||
<input v-model="user.email" placeholder="email" />
|
<input v-model="user.email" placeholder="email" />
|
||||||
<input v-model="user.password" placeholder="password" />
|
<input v-model="user.password" placeholder="password" />
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const router = useRouter();
|
|||||||
|
|
||||||
const user = ref<User>({
|
const user = ref<User>({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "",
|
username: "",
|
||||||
email: "",
|
email: "",
|
||||||
password: ""
|
password: ""
|
||||||
});
|
});
|
||||||
@@ -46,7 +46,7 @@ async function save(): Promise<void> {
|
|||||||
<h2>{{ id ? "Edit User" : "Create User" }}</h2> <!-- omg I love ternary operator :D -->
|
<h2>{{ id ? "Edit User" : "Create User" }}</h2> <!-- omg I love ternary operator :D -->
|
||||||
|
|
||||||
<form @submit.prevent="save">
|
<form @submit.prevent="save">
|
||||||
<input v-model="user.name" placeholder="Name" />
|
<input v-model="user.username" placeholder="Name" />
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
<button type="submit">Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ function logout() {
|
|||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr v-for="user in store.users" :key="user.id">
|
<tr v-for="user in store.users" :key="user.id">
|
||||||
<td>{{ user.name }}</td>
|
<td>{{ user.username }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
<router-link :to="`/user/${user.id}`" custom v-slot="{ navigate }">
|
<router-link :to="`/user/${user.id}`" custom v-slot="{ navigate }">
|
||||||
|
|||||||
24
scripts/DEV_README.md
Normal file
24
scripts/DEV_README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
## These are some notes for development
|
||||||
|
# contains some helpful tips, commands, and knowledge
|
||||||
|
|
||||||
|
Resetting the database (for dev):
|
||||||
|
> set development evironment (specify non-docker network and db password)
|
||||||
|
> dotnet ef database drop
|
||||||
|
> dotnet ef migrations remove
|
||||||
|
> if above errors, dotnet ef database update 0
|
||||||
|
> dotnet ef migrations add InitialCreate
|
||||||
|
|
||||||
|
To see live logs:
|
||||||
|
sudo docker logs -f -t agologum-api
|
||||||
|
|
||||||
|
public user:
|
||||||
|
> username=bard
|
||||||
|
> password=Public*890
|
||||||
|
|
||||||
|
chrome dev tools troubleshooting
|
||||||
|
> response body: Network => url endpoint => Response => expand
|
||||||
|
|
||||||
|
Always test build before committing
|
||||||
|
> for the client: $ npm run dev
|
||||||
|
> for the api: $ dotnet build
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
Resetting the database (for dev):
|
|
||||||
> set development evironment (specify non-docker network and db password)
|
|
||||||
> dotnet ef database drop
|
|
||||||
> dotnet ef migrations remove
|
|
||||||
> if above errors, dotnet ef database update 0
|
|
||||||
> dotnet ef migrations add InitialCreate
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user