172 lines
5.2 KiB
JavaScript
172 lines
5.2 KiB
JavaScript
daddy.controller("loginCtrlr", function($scope, $cookies, $location, $http, stateData){
|
|
|
|
let titles = {
|
|
login : "Login!",
|
|
signup : "Not a Member?"
|
|
}
|
|
$scope.titles = titles
|
|
|
|
let message = {
|
|
start : "Feel free to",
|
|
link : "Sign Up",
|
|
end : "at any time!"
|
|
}
|
|
$scope.message = message
|
|
|
|
$scope.setSignup = () => {
|
|
stateData.setPage("forum")
|
|
$location.path("/signup")
|
|
}
|
|
|
|
$scope.login = () => {
|
|
$scope.status = true
|
|
$scope.loginStatus = "Logging you in..."
|
|
console.log("logging in")
|
|
console.log("requesting authentication from server")
|
|
$http({
|
|
url : server + "/auth/login?userName="+$scope.user.username+"&userPass="+$scope.user.password,
|
|
method : "GET"
|
|
}).then((res) => {
|
|
console.log(res)
|
|
if (res.status == 200) {
|
|
console.log("request granted")
|
|
let today = new Date()
|
|
let expired = new Date(today)
|
|
expired.setDate(today.getDate()+1)
|
|
$cookies.putObject('user', res.data, {expires : expired})
|
|
console.log("set cookie")
|
|
stateData.setUser(res.data)
|
|
console.log("set data")
|
|
stateData.setPage("forum")
|
|
$location.path("/")
|
|
}
|
|
}).catch((res) => {
|
|
if (res.status == 400) {
|
|
$scope.loginStatus = "Incorrect information!"
|
|
console.log("request denied")
|
|
} else if (res.status == 500) {
|
|
$scope.loginStatus = "Login Failed."
|
|
console.log("something went wrong: " + res)
|
|
}
|
|
})
|
|
}
|
|
|
|
})
|
|
|
|
daddy.controller("signupCtrlr", function($scope, $http, $location, $timeout, stateData) {
|
|
|
|
let titles = {
|
|
form : "Sign up here!",
|
|
success : "Signup Success!"
|
|
}
|
|
$scope.titles = titles
|
|
|
|
let message = {
|
|
start : "You account has been created!",
|
|
line2 : "Feel free to",
|
|
link : "Login",
|
|
end : "whenever you like."
|
|
}
|
|
$scope.message = message
|
|
|
|
$scope.success = false
|
|
$scope.exists = false
|
|
$scope.status = false
|
|
|
|
$scope.setLogin = () => {
|
|
stateData.setPage("forum")
|
|
$location.path("/login")
|
|
}
|
|
|
|
$scope.signup = () => {
|
|
$scope.userExists()
|
|
$scope.passwordsMatch()
|
|
$scope.emailGood()
|
|
|
|
$timeout(function() {
|
|
if ($scope.match && !$scope.exists && $scope.goodemail) {
|
|
$scope.status = false
|
|
$scope.submit()
|
|
} else {
|
|
$scope.status = true
|
|
$scope.signupStatus = "Please correct errors above."
|
|
}
|
|
}, 1000)
|
|
}
|
|
|
|
$scope.emailGood = () => {
|
|
if (validateEmail($scope.user.email)) {
|
|
$scope.goodemail = true
|
|
$scope.emailError = ""
|
|
} else {
|
|
$scope.goodemail = false
|
|
$scope.emailError = "< invalid email."
|
|
}
|
|
}
|
|
|
|
$scope.passwordsMatch = () => {
|
|
if ($scope.user.password != $scope.user.confirmPassword) {
|
|
$scope.match = false
|
|
$scope.passwordError = "< password does not match."
|
|
} else {
|
|
$scope.match = true
|
|
$scope.passwordError = ""
|
|
}
|
|
}
|
|
|
|
$scope.submit = () => {
|
|
let formData = new FormData()
|
|
formData.append('userName', $scope.user.username)
|
|
formData.append('userPass', $scope.user.password)
|
|
formData.append('userEmail', $scope.user.email)
|
|
$http({
|
|
url : server + "/auth/signup",
|
|
method : "POST",
|
|
data : formData,
|
|
headers : { 'Content-Type' : undefined },
|
|
transformRequest : angular.identity
|
|
}).then((res) => {
|
|
if (res.status == 200) {
|
|
console.log("user created successfully")
|
|
$scope.success = true
|
|
$scope.signupForm.$setPristine()
|
|
$scope.user.username = ""
|
|
$scope.user.password = ""
|
|
$scope.user.confirmPassword = ""
|
|
$scope.user.email = ""
|
|
}
|
|
}).catch((res) => {
|
|
if (res.status == 500) {
|
|
console.log("whoops...")
|
|
}
|
|
})
|
|
}
|
|
|
|
$scope.userExists = () => {
|
|
console.log("checking username is used?")
|
|
let formData = new FormData()
|
|
formData.append('userName', $scope.user.username)
|
|
$http({
|
|
url : server + "/auth/exists",
|
|
method : "POST",
|
|
data : formData,
|
|
headers : { 'Content-Type' : undefined },
|
|
transformRequest : angular.identity
|
|
}).then((res) => {
|
|
if (res.status == 200) {
|
|
console.log(res.data)
|
|
if (res.data == true) {
|
|
$scope.exists = true
|
|
$scope.usernameError= "< username already exists."
|
|
} else {
|
|
$scope.exists = false
|
|
$scope.usernameError = ""
|
|
}
|
|
}
|
|
}).catch((res) => {
|
|
if (res.status == 500) {
|
|
console.log ("something went wrong")
|
|
}
|
|
})
|
|
}
|
|
}) |