Commit 7ee796ad authored by Ghitha Dinan's avatar Ghitha Dinan

change secret

parent dbaf13e1
package id.go.kemenag.madrasah.pmrms.auth.controller
import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.ForgotPasswordRequest
import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.LoginRequest
import id.go.kemenag.madrasah.pmrms.auth.model.response.ReturnData
import id.go.kemenag.madrasah.pmrms.auth.service.AuthService
......@@ -22,6 +23,11 @@ class AuthController {
return service.login(request)
}
@PostMapping(value = ["forgot-password"], produces = ["application/json"])
fun forgotPassword(@Valid @RequestBody request: ForgotPasswordRequest): ResponseEntity<ReturnData> {
return service.forgotPassword(request)
}
@GetMapping(value = ["detail"], produces = ["application/json"])
fun detail(): ResponseEntity<ReturnData> {
return service.detail()
......
package id.go.kemenag.madrasah.pmrms.auth.model.request.auth
import id.go.kemenag.madrasah.pmrms.auth.constant.VALIDATOR_MSG_REQUIRED
import id.go.kemenag.madrasah.pmrms.auth.validator.EmailValidator
import javax.validation.constraints.NotEmpty
class ForgotPasswordRequest(
@field:NotEmpty(message = "Email $VALIDATOR_MSG_REQUIRED")
@field:EmailValidator
var email: String? = null
)
package id.go.kemenag.madrasah.pmrms.auth.pojo
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonIgnore
import java.util.*
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.Id
import javax.persistence.Table
@Entity
@Table(name = "users_forgot_password", schema = "auth")
data class UsersForgotPassword(
@Id
@Column(name = "id")
var id: String? = UUID.randomUUID().toString(),
@Column(name = "user_id")
var userId: String? = null,
@Column(name = "created_at")
@get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss", timezone = "GMT+7")
var createdAt: Date? = Date(),
@Column(name = "updated_at")
@get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss", timezone = "GMT+7")
var updatedAt: Date? = Date(),
@Column(name = "active")
@JsonIgnore
var active: Boolean? = true
)
package id.go.kemenag.madrasah.pmrms.auth.repository
import id.go.kemenag.madrasah.pmrms.auth.pojo.UsersForgotPassword
import org.springframework.data.jpa.repository.JpaRepository
import java.util.*
interface UserForgotPasswordRepository : JpaRepository<UsersForgotPassword, String> {
fun findByIdAndActive(id: String?, active: Boolean = true): Optional<UsersForgotPassword>
}
......@@ -12,10 +12,13 @@ import id.go.kemenag.madrasah.pmrms.auth.exception.BadRequestException
import id.go.kemenag.madrasah.pmrms.auth.helpers.getUserLogin
import id.go.kemenag.madrasah.pmrms.auth.helpers.responseNotFound
import id.go.kemenag.madrasah.pmrms.auth.helpers.responseSuccess
import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.ForgotPasswordRequest
import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.LoginRequest
import id.go.kemenag.madrasah.pmrms.auth.model.response.ReturnData
import id.go.kemenag.madrasah.pmrms.auth.model.response.jwt.JwtAuthenticationResponse
import id.go.kemenag.madrasah.pmrms.auth.pojo.Users
import id.go.kemenag.madrasah.pmrms.auth.pojo.UsersForgotPassword
import id.go.kemenag.madrasah.pmrms.auth.repository.UserForgotPasswordRepository
import id.go.kemenag.madrasah.pmrms.auth.repository.UserRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
......@@ -29,6 +32,9 @@ class AuthService {
@Autowired
private lateinit var repoUser: UserRepository
@Autowired
private lateinit var repoUserForgotPassword: UserForgotPasswordRepository
fun login(request: LoginRequest): ResponseEntity<ReturnData> {
try {
val data = repoUser.findByEmailAndActive(request.email)
......@@ -77,4 +83,19 @@ class AuthService {
throw e
}
}
fun forgotPassword(request: ForgotPasswordRequest): ResponseEntity<ReturnData> {
try {
val data = repoUser.findByEmailAndActive(request.email)
if (data.isPresent) {
val userForgotPassword = UsersForgotPassword()
userForgotPassword.userId = data.get().id
repoUserForgotPassword.save(userForgotPassword)
return responseSuccess()
}
return responseNotFound("User $VALIDATOR_MSG_NOT_FOUND")
} catch (e: Exception) {
throw e
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment