-
Notifications
You must be signed in to change notification settings - Fork 0
/
employeesViewModel.swift
73 lines (49 loc) · 1.41 KB
/
employeesViewModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// employeesViewModel.swift
// RestaurantApp
//
// Created by Maciej Bichajło on 11/01/2024.
//
enum employeesViewState{
case login
case logged
case edit
case order
case none
}
enum loginErrors:Error{
case wrongUsername
case wrongPassword
case emptyFields
}
import SwiftUI
import CoreData
class EmployeesViewModel:ObservableObject{
private let context=PersistenceController.shared.container.viewContext
// MARK: - Login Variables
@Published var username=""
@Published var password=""
@Published var state:employeesViewState = .none
@Published var didLogIn = false
private let correctUsername = "admin"
private let correctPassword = "admin"
@Published var incorrect = false
@Published var empty = false
@Published var generic = false
//MARK: - Login Functions
func login() throws -> Bool{
if password.isEmpty || username.isEmpty{
throw loginErrors.emptyFields
}
if password==correctPassword && username == correctUsername{
state = .logged
didLogIn = true
return true
}else if password==correctPassword{
throw loginErrors.wrongUsername
}else if username == correctUsername{
throw loginErrors.wrongPassword
}
return false
}
}