feat(wip): login
This commit is contained in:
@@ -8,5 +8,6 @@ import { User } from './entities/user.entity';
|
||||
imports: [TypeOrmModule.forFeature([User])],
|
||||
controllers: [UsersController],
|
||||
providers: [UsersService],
|
||||
exports: [UsersService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
|
||||
@@ -4,6 +4,8 @@ import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
||||
import { hashPassword } from '../helper/hash_password';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -13,7 +15,12 @@ export class UsersService {
|
||||
) {}
|
||||
|
||||
async create(createUserDto: CreateUserDto) {
|
||||
const result = await this.usersRepository.insert(createUserDto);
|
||||
const salt = randomStringGenerator();
|
||||
const result = await this.usersRepository.insert({
|
||||
username: createUserDto.username,
|
||||
password: await hashPassword(createUserDto.password, salt),
|
||||
salt,
|
||||
});
|
||||
|
||||
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
||||
}
|
||||
@@ -81,4 +88,12 @@ export class UsersService {
|
||||
|
||||
await this.usersRepository.delete(id);
|
||||
}
|
||||
|
||||
async findOneByUsername(username: string) {
|
||||
return this.usersRepository.findOneOrFail({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user