Newer
Older
CactusServer / src / main / java / cactusServer / resources / AccountsRest.java
y-ota on 17 May 2018 1 KB login logoutを追加
package cactusServer.resources;

import java.net.URI;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

import cactusServer.entities.Account;
import cactusServer.models.Accounts;

@Path("/AccountsRest")
public class AccountsRest {
	@POST
	@Path("/login")
	@Produces(MediaType.APPLICATION_JSON)
	public URI loginAccount(@QueryParam("userID") String userID, @QueryParam("userPass") String userPass) {
		if(Accounts.getInstance().getAccount(userID).getPass().equals(userPass)) {
			return URI.create(userID);
		}else {
			return URI.create("failed login attempt");
		}
	}
 
	@POST
	@Path("/logout")
	@Produces(MediaType.APPLICATION_JSON)
	public String logoutAccount(@QueryParam("userID") String userID) {
		return Accounts.getInstance().logoutAccount(userID);
	}

	@POST
	@Path("/createAccount")
	@Produces(MediaType.APPLICATION_JSON)
	public Account create(@QueryParam("userID") String userID, @QueryParam("userName") String userName,
			@QueryParam("userPass") String userPass) {
		return Accounts.getInstance().createAcount(userID, userName, userPass);
	}

	@GET
	@Path("/getAccount")
	@Produces(MediaType.APPLICATION_JSON)
	public Account getAccount(@QueryParam("userID") String userID) {
		return Accounts.getInstance().getAccount(userID);
	}
}