-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOTPVerification.swift
95 lines (86 loc) · 3.67 KB
/
OTPVerification.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import SwiftUI
import Firebase
import FirebaseAuth
import Combine
struct OTPVerification: View {
@State var code = ""
@Binding var show : Bool
@Binding var ID : String
@State var msg = ""
@State var alert = false
@Binding var no : String
@State private var Tapped = false
@State private var ChangeNo = false
var size = UIScreen.main.bounds
var body: some View {
ZStack{
Color.EuleBackground.edgesIgnoringSafeArea(.all)
VStack(alignment: .center, spacing: 10){
VStack(alignment: .center, spacing: 20){
Spacer()
.frame( height: size.width/10)
Text("You’re just a few steps away ")
Text("Please enter the one time password \n recived on \(no)")
.font(.EuleLabel)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
//change number
NavigationLink(destination: PhoneNumber(), isActive: $ChangeNo) { EmptyView() }
Button(action: {
self.ChangeNo = true
}){
Text("Change Number")
}
Spacer()
.frame( height: 50)
TextField("000000", text: self.$code)
.font(.EuleHeading)
.fixedSize()
.keyboardType(.numberPad)
.textContentType(.oneTimeCode)
.fixedSize()
.accentColor(Color.EuleGreen)
.animation(.linear)
.onReceive(Just(self.code)) { inputValue in
if inputValue.count > 6 {
self.code.removeLast()
}
}
Spacer()
Button(action: {
// otp auth
if code.count == 6 {
let credential = PhoneAuthProvider.provider().credential(withVerificationID: self.ID, verificationCode: self.code)
Auth.auth().signIn(with: credential) { (res, err) in
if err != nil{
self.msg = (err?.localizedDescription)!
self.alert.toggle()
return
}
else{
print("\(Auth.auth().currentUser?.uid ?? "")")
UserDefaults.standard.set(true, forKey: "status")
NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil)
}
}
}
}){
Text("Continue")
}.buttonStyle(EuleGreenButton())
.opacity(!(code.count < 6) ? 1 : 0.5)
.disabled(!(code.count < 6) ? false : true)
}.background(Color.white)
}
.cornerRadius(15)
.frame(width: (size.width) )
.padding(.top, 40)
}
.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(true)
.accentColor(.EuleGreen)
//error alert
.alert(isPresented: $alert) {
Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text("Ok")))
}
}
}