Skip to content

Instantly share code, notes, and snippets.

@tuesd4y
Last active February 28, 2019 12:39
Show Gist options
  • Save tuesd4y/09987336b659919f792d2b309a255b2c to your computer and use it in GitHub Desktop.
Save tuesd4y/09987336b659919f792d2b309a255b2c to your computer and use it in GitHub Desktop.
package at.triply.backend.eventbackend.security
import at.triply.backend.eventbackend.data.entities.EventManager
import at.triply.backend.eventbackend.data.repositories.EventManagerRepository
import org.springframework.data.rest.webmvc.BasePathAwareController
import org.springframework.http.ResponseEntity
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
@BasePathAwareController
@RequestMapping("/users")
class EventManagerController(val eventManagerRepository: EventManagerRepository,
val passwordEncoder: PasswordEncoder) {
@PostMapping("/signup")
@ResponseBody
fun signUp(@RequestBody user: EventManager): ResponseEntity<User> {
val encodedPassword = passwordEncoder.encode(user.password)
return ResponseEntity.ok(
eventManagerRepository.save(user.copy(password = encodedPassword))
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment