// Path: src/main/java/com/jeanchampemont/notedown/security/AuthenticationService.java
// @Service
// public class AuthenticationService {
//     private UserRepository userRepository;
// 
//     private AuthenticationManager authenticationManager;
// 
//     @Autowired
//     public AuthenticationService(UserRepository userRepository, AuthenticationManager authenticationManager) {
//         this.userRepository = userRepository;
//         this.authenticationManager = authenticationManager;
//     }
// 
//     public User getCurrentUser() {
//         String email = SecurityContextHolder.getContext().getAuthentication().getName();
//         return userRepository.findByEmailIgnoreCase(email);
//     }
// 
//     public boolean isAuthenticated() {
//         return (SecurityContextHolder.getContext().getAuthentication() != null);
//     }
// 
//     public void newAuthentication(String email, String password) {
//         Authentication request = new UsernamePasswordAuthenticationToken(email, password);
//         Authentication result = authenticationManager.authenticate(request);
//         SecurityContextHolder.getContext().setAuthentication(result);
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/User.java
// @Entity
// @Table(name = "user_account")
// public class User {
//     @Id
//     @GeneratedValue(strategy = GenerationType.TABLE)
//     private long id;
// 
//     @Column(name = "email", unique = true, length = 64)
//     private String email;
// 
//     @Column(name = "password", length = 60)
//     private String password;
// 
//     @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
//     private Set<Note> notes = new HashSet<>();
// 
//     @Column(name = "locale", length = 2)
//     private String locale;
// 
//     @Column(name = "display_name", length = 64)
//     private String displayName;
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public Set<Note> getNotes() {
//         return notes;
//     }
// 
//     public void setNotes(Set<Note> notes) {
//         this.notes = notes;
//     }
// 
//     public String getLocale() {
//         return locale;
//     }
// 
//     public void setLocale(String locale) {
//         this.locale = locale;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/repository/UserRepository.java
// public interface UserRepository extends CrudRepository<User, Long> {
//     User findByEmailIgnoreCase(String email);
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/utils/exception/OperationNotAllowedException.java
// public class OperationNotAllowedException extends RuntimeException {
// 
// }


import com.jeanchampemont.notedown.security.AuthenticationService;
import com.jeanchampemont.notedown.user.persistence.User;
import com.jeanchampemont.notedown.user.persistence.repository.UserRepository;
import com.jeanchampemont.notedown.utils.exception.OperationNotAllowedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
/*
 * Copyright (C) 2014, 2015 NoteDown
 *
 * This file is part of the NoteDown project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jeanchampemont.notedown.user;



/**
 * This service manages users of the application.
 *
 * @author Jean Champémont
 */
@Service
public class UserService {

    private AuthenticationService authenticationService;

    private UserRepository repo;

    private PasswordEncoder encoder;

    @Autowired
// Path: src/main/java/com/jeanchampemont/notedown/security/AuthenticationService.java
// @Service
// public class AuthenticationService {
//     private UserRepository userRepository;
// 
//     private AuthenticationManager authenticationManager;
// 
//     @Autowired
//     public AuthenticationService(UserRepository userRepository, AuthenticationManager authenticationManager) {
//         this.userRepository = userRepository;
//         this.authenticationManager = authenticationManager;
//     }
// 
//     public User getCurrentUser() {
//         String email = SecurityContextHolder.getContext().getAuthentication().getName();
//         return userRepository.findByEmailIgnoreCase(email);
//     }
// 
//     public boolean isAuthenticated() {
//         return (SecurityContextHolder.getContext().getAuthentication() != null);
//     }
// 
//     public void newAuthentication(String email, String password) {
//         Authentication request = new UsernamePasswordAuthenticationToken(email, password);
//         Authentication result = authenticationManager.authenticate(request);
//         SecurityContextHolder.getContext().setAuthentication(result);
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/User.java
// @Entity
// @Table(name = "user_account")
// public class User {
//     @Id
//     @GeneratedValue(strategy = GenerationType.TABLE)
//     private long id;
// 
//     @Column(name = "email", unique = true, length = 64)
//     private String email;
// 
//     @Column(name = "password", length = 60)
//     private String password;
// 
//     @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
//     private Set<Note> notes = new HashSet<>();
// 
//     @Column(name = "locale", length = 2)
//     private String locale;
// 
//     @Column(name = "display_name", length = 64)
//     private String displayName;
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public Set<Note> getNotes() {
//         return notes;
//     }
// 
//     public void setNotes(Set<Note> notes) {
//         this.notes = notes;
//     }
// 
//     public String getLocale() {
//         return locale;
//     }
// 
//     public void setLocale(String locale) {
//         this.locale = locale;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/repository/UserRepository.java
// public interface UserRepository extends CrudRepository<User, Long> {
//     User findByEmailIgnoreCase(String email);
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/utils/exception/OperationNotAllowedException.java
// public class OperationNotAllowedException extends RuntimeException {
// 
// }


// Path: src/main/java/com/jeanchampemont/notedown/user/UserService.java
import com.jeanchampemont.notedown.security.AuthenticationService;
import com.jeanchampemont.notedown.user.persistence.User;
import com.jeanchampemont.notedown.user.persistence.repository.UserRepository;
import com.jeanchampemont.notedown.utils.exception.OperationNotAllowedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;

/*
 * Copyright (C) 2014, 2015 NoteDown
 *
 * This file is part of the NoteDown project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jeanchampemont.notedown.user;



/**
 * This service manages users of the application.
 *
 * @author Jean Champémont
 */
@Service
public class UserService {

    private AuthenticationService authenticationService;

    private UserRepository repo;

    private PasswordEncoder encoder;

    @Autowired
    public UserService(AuthenticationService authenticationService, UserRepository repo, PasswordEncoder encoder) {