package com.theironyard.controllers;

import com.theironyard.entities.User;
import com.theironyard.services.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * Created by Dan on 7/19/16.
 */
@RestController
public class VertoSwapController {

    @Autowired
    UserRepository users;

    @RequestMapping(path = "/login", method = RequestMethod.POST)
    public void login(HttpSession session, @RequestBody User user) {
        //User userFromDB = users.findByName
    }
}

@@ -117,16 +117,66 @@
 sitory;%0A
+import com.theironyard.utilities.PasswordStorage;%0A
 import o
@@ -230,16 +230,66 @@
 owired;%0A
+import org.springframework.stereotype.Controller;%0A
 import o
@@ -468,71 +468,8 @@
 hod;
-%0Aimport org.springframework.web.bind.annotation.RestController;
 %0A%0Aim
@@ -549,12 +549,8 @@
 */%0A@
-Rest
 Cont
@@ -634,16 +634,28 @@
 users;%0A%0A
+%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A
     @Req
@@ -675,21 +675,30 @@
 ath = %22/
-login
+account-create
 %22, metho
@@ -736,18 +736,28 @@
 lic 
-void login
+String createAccount
 (Htt
@@ -778,31 +778,590 @@
 on, 
-@RequestBody User user)
+String username, String password) throws Exception %7B%0A        User user = users.findByName(username);%0A        if (user != null) %7B%0A            throw new Exception(%22Username unavailable.%22);%0A        %7D%0A        else %7B%0A            user = new User(username, PasswordStorage.createHash(password));%0A            users.save(user);%0A            session.setAttribute(%22username%22, username);%0A        %7D%0A        return %22redirect:/%22;%0A    %7D%0A%0A    @RequestMapping(path = %22/login%22, method = RequestMethod.POST)%0A    public String login(HttpSession session, String username, String password) throws Exception
  %7B%0A 
@@ -1371,10 +1371,8 @@
     
-//
 User
@@ -1401,16 +1401,530 @@
 ndByName
+(username);%0A        if (userFromDB == null) %7B%0A            return %22redirect:/create-account%22;%0A        %7D%0A        else if (!PasswordStorage.verifyPassword(password, userFromDB.getPassword())) %7B%0A            throw new Exception(%22Wrong password.%22);%0A        %7D%0A        session.setAttribute(%22username%22, username);%0A        return %22redirect:/%22;%0A    %7D%0A%0A    @RequestMapping(path = %22/logout%22, method = RequestMethod.POST)%0A    public String logout(HttpSession session) %7B%0A        session.invalidate();%0A        return %22redirect:/%22;
 %0A    %7D%0A%7D

Create login, logout, create account routes