parent
31185076e2
commit
3ae4fbf7ab
@ -0,0 +1,25 @@ |
|||||||
|
// |
||||||
|
// AccountView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 21/02/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct AccountView: View { |
||||||
|
|
||||||
|
var user: User |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
Form { |
||||||
|
NavigationLink("Change password") { |
||||||
|
ChangePasswordView() |
||||||
|
} |
||||||
|
}.navigationTitle(user.username) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
AccountView(user: User(username: "coco")) |
||||||
|
} |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
// |
||||||
|
// ChangePasswordView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 21/02/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
struct ChangePasswordView: View { |
||||||
|
|
||||||
|
@State var password1: String = "staxkikoo" |
||||||
|
@State var password2: String = "staxkikoo" |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
|
||||||
|
Form { |
||||||
|
|
||||||
|
SecureField("Password", text: self.$password1) |
||||||
|
.autocorrectionDisabled() |
||||||
|
.textInputAutocapitalization(.never) |
||||||
|
SecureField("Password again", text: self.$password2) |
||||||
|
.autocorrectionDisabled() |
||||||
|
.textInputAutocapitalization(.never) |
||||||
|
|
||||||
|
Section { |
||||||
|
Button(action: { |
||||||
|
self._changePassword() |
||||||
|
}, label: { |
||||||
|
Text("Change password") |
||||||
|
}) |
||||||
|
.frame(maxWidth: .infinity) |
||||||
|
} |
||||||
|
} |
||||||
|
.navigationTitle("Change password") |
||||||
|
} |
||||||
|
|
||||||
|
fileprivate func _changePassword() { |
||||||
|
guard let service = Store.main.service else { |
||||||
|
return |
||||||
|
} |
||||||
|
Task { |
||||||
|
do { |
||||||
|
_ = try await service.changePassword(password1: self.password1, password2: self.password2) |
||||||
|
} catch { |
||||||
|
Logger.error(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
ChangePasswordView() |
||||||
|
} |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
// |
||||||
|
// UserView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 21/02/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
struct MainUserView: View { |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
|
||||||
|
// if let user = , Store.main.hasToken() { |
||||||
|
// AccountView(user: user) |
||||||
|
// } else { |
||||||
|
// LoginView() |
||||||
|
// } |
||||||
|
|
||||||
|
Text("test") |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
MainUserView() |
||||||
|
} |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
// |
||||||
|
// User.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 21/02/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import Foundation |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
class User: UserBase { |
||||||
|
public var id: String = Store.randomId() |
||||||
|
public var username: String |
||||||
|
public var email: String? |
||||||
|
|
||||||
|
init(username: String, email: String? = nil) { |
||||||
|
self.username = username |
||||||
|
self.email = email |
||||||
|
} |
||||||
|
|
||||||
|
public func uuid() throws -> UUID { |
||||||
|
if let uuid = UUID(uuidString: self.id) { |
||||||
|
return uuid |
||||||
|
} |
||||||
|
throw UUIDError.cantConvertString(string: self.id) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
class UserCreationForm: User, UserPasswordBase { |
||||||
|
|
||||||
|
init(username: String, password: String, email: String?) { |
||||||
|
self.password = password |
||||||
|
super.init(username: username, email: email) |
||||||
|
} |
||||||
|
|
||||||
|
required init(from decoder: Decoder) throws { |
||||||
|
fatalError("init(from:) has not been implemented") |
||||||
|
} |
||||||
|
|
||||||
|
public var password: String |
||||||
|
|
||||||
|
private enum CodingKeys: String, CodingKey { |
||||||
|
case password |
||||||
|
} |
||||||
|
|
||||||
|
override func encode(to encoder: Encoder) throws { |
||||||
|
try super.encode(to: encoder) |
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self) |
||||||
|
try container.encode(self.password, forKey: .password) |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue