package com.gmscheduler.model;

import com.gmscheduler.model.Person;
import com.gmscheduler.model.DatabaseManager;

/**
 * The Login Utility is the buisness logic for loging-in and verifying password. 
 *
 * @author Peter Deschere
 * @author Rebecca Beale
 * @author Jason Fillo
 * @author Andrew Toy
 * @version 1.1
 * @see com.gmscheduler.model.Person
 * @see com.gmscheduler.model.DatabaseManager;
 */
public class LoginUtil {
	
	public Person createUser(String name, String pw) {
		Person p;
		p = dm.loadPersonByName(name);
		
		// check if person already exists
		if (p.isEmpty()) {
			p = new Person(name,pw);
			p = dm.storePerson(p);
		} else {
			p = new Person();
		}
		
		return p;
	}
	
	public Person login(String name, String pw) {
		Person p;
		p = dm.loadPersonByName(name);
		
		//pw's don't match
		if (p.getPassword().compareTo(pw)!=0) {p = new Person();}
		
		return p;
	}
	
	private DatabaseManager dm = new DatabaseManager();
}