mvcgen 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -15
- data/lib/mvcgen/generator.rb +61 -1
- data/lib/mvcgen/version.rb +1 -1
- data/lib/templates/default/swift/Controllers/Login/ForgetPasswordVC.swift +32 -39
- data/lib/templates/default/swift/Controllers/Login/LoginVC.swift +21 -11
- data/lib/templates/default/swift/Controllers/Login/RegisterVC.swift +69 -59
- data/lib/templates/default/swift/Controllers/Notifications/Cells/NotificationCell.swift +28 -1
- data/lib/templates/default/swift/Controllers/Notifications/NotificationsVC.swift +17 -27
- data/lib/templates/default/swift/Controllers/OtherLogin/ForgetPasswordTVC.swift +9 -10
- data/lib/templates/default/swift/Controllers/OtherLogin/LoginTVC.swift +1 -1
- data/lib/templates/default/swift/Controllers/OtherLogin/OtherRegisterVC.swift +11 -10
- data/lib/templates/default/swift/Controllers/OtherLogin/SelectLanguageVC.swift +22 -21
- data/lib/templates/default/swift/Controllers/OtherLogin/TermsAndConditionsVC.swift +8 -7
- data/lib/templates/default/swift/Controllers/Profile/AboutUsVC.swift +23 -11
- data/lib/templates/default/swift/Controllers/Profile/Cells/AboutUsImageCell.swift +21 -5
- data/lib/templates/default/swift/Controllers/Profile/Cells/DescriptionCell.swift +10 -0
- data/lib/templates/default/swift/Controllers/Profile/Cells/DestinationCell.swift +5 -0
- data/lib/templates/default/swift/Controllers/Profile/Cells/FavoriteCollectionCell.swift +2 -0
- data/lib/templates/default/swift/Controllers/Profile/Cells/ImagesCollectionViewCell.swift +12 -0
- data/lib/templates/default/swift/Controllers/Profile/ProfileContainerVC.swift +18 -14
- data/lib/templates/default/swift/Controllers/Profile/ProfileTVC.swift +65 -85
- data/lib/templates/default/swift/Controllers/Tutorial/TutorialVC.swift +12 -9
- data/lib/templates/default/swift/Extensions/Buttons.swift +0 -12
- data/lib/templates/default/swift/Extensions/{ArrayDuplicates.swift → Utils+Array.swift} +1 -1
- data/lib/templates/default/swift/Extensions/{Images.swift → Utils+Images.swift} +8 -7
- data/lib/templates/default/swift/Extensions/Utils+String.swift +34 -0
- data/lib/templates/default/swift/Extensions/Utils+UIButton.swift +21 -0
- data/lib/templates/default/swift/Extensions/{UIColorExtensions.swift → Utils+UIColor.swift} +1 -1
- data/lib/templates/default/swift/Extensions/{TableViewEmptyView.swift → Utils+UITableView.swift} +1 -2
- data/lib/templates/default/swift/Extensions/Utils+UITextField.swift +22 -0
- data/lib/templates/default/swift/Extensions/{GradientView.swift → Utils+UIView.swift} +82 -2
- data/lib/templates/default/swift/Extensions/{TapEffectExtension.swift → Utils+UIViewController.swift} +18 -1
- data/lib/templates/default/swift/Helper/Utils.swift +1 -1
- data/lib/templates/default/swift/UI/Storyboards/Home.storyboard +4 -4
- data/lib/templates/default/swift/UI/Views/EmptyTableView/Xibs/EmptyTableLabelView.xib +1 -1
- metadata +11 -18
- data/lib/templates/default/swift/Assets.xcassets/alert_beach.imageset/Contents.json +0 -21
- data/lib/templates/default/swift/Assets.xcassets/alert_beach.imageset/icons8-beach-64.png +0 -0
- data/lib/templates/default/swift/Assets.xcassets/alert_nobaggage.imageset/Contents.json +0 -21
- data/lib/templates/default/swift/Assets.xcassets/alert_nobaggage.imageset/icons8-no-baggage-100.png +0 -0
- data/lib/templates/default/swift/Assets.xcassets/alert_signpost.imageset/Contents.json +0 -21
- data/lib/templates/default/swift/Assets.xcassets/alert_signpost.imageset/icons8-signpost-64.png +0 -0
- data/lib/templates/default/swift/Assets.xcassets/alert_sunbed.imageset/Contents.json +0 -21
- data/lib/templates/default/swift/Assets.xcassets/alert_sunbed.imageset/sunbed.png +0 -0
- data/lib/templates/default/swift/Extensions/HideKeyboard.swift +0 -22
- data/lib/templates/default/swift/Extensions/InnerShadowExtension.swift +0 -83
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd00291f4c2e3b1d3b3da10080f0df0a4cd0df4d
|
4
|
+
data.tar.gz: 36b8b66d0fc2a889b29d18dae82ccffa2ec97a9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '089345d9299dc54561c612152eef2aae89768ed5af101f124ba2a1673b877003be6825b3213fe3d8e35a56a3e337a40c22f0718c2e833de99a2b8c80f4f47605'
|
7
|
+
data.tar.gz: 79090f4ae74d29cc0cb075b7becd65fc6454543637cab070a7449bdffa93111e1d905aafee10b9b133b92fe9edf52b45a7a02eb5b93bedc545784db3c5d2e3c6
|
data/README.md
CHANGED
@@ -7,11 +7,9 @@ Gem to generate MVC starting modules to use them in your Swift projects
|
|
7
7
|
The implementation scheme returned by this generator is hardly inspired in the example and post of vipergen, https://rubygems.org/gems/vipergen/versions/0.2.6 .
|
8
8
|
|
9
9
|
- [Features](#features)
|
10
|
-
- [Changelog](#changelog-0.1)
|
11
|
-
- [Expected in version 0.2](#expected-in-version-0.2)
|
12
10
|
- [MVC files structure](#mvc-files-structure)
|
13
|
-
- [How to install mvcgen](#how-to-install-
|
14
|
-
- [How to generate a MVC module with a given name?](#how-to-generate-
|
11
|
+
- [How to install mvcgen](#how-to-install-mvcgen)
|
12
|
+
- [How to generate a MVC module with a given name?](#how-to-generate-a-MVC-module-with-a-given-name?)
|
15
13
|
- [Developer tips](#developer-tips)
|
16
14
|
- [Update the gem](#update-the-gem)
|
17
15
|
- [Add a new template](#add-a-new-template)
|
@@ -117,7 +115,7 @@ sudo gem install mvcgen
|
|
117
115
|
If everything were right, you should have now the mvcgen command available in your system console
|
118
116
|
|
119
117
|
## How to generate a MVC module with a given name?
|
120
|
-
You have just to execute the following command standing on your project
|
118
|
+
You have just to execute the following command standing on your project root folder
|
121
119
|
```bash
|
122
120
|
mvcgen generate YourProjectName --path=./
|
123
121
|
```
|
@@ -127,28 +125,28 @@ And then the files structure will be automatically created and added to the proj
|
|
127
125
|
### Update the gem
|
128
126
|
When the gem is updated it has to be reported to the gem repository. I followed this tutorial http://amaras-tech.co.uk/article/43/Creating_executable_gems that basically says that once you have your gem ready execute:
|
129
127
|
```bash
|
130
|
-
gem build
|
131
|
-
gem install
|
132
|
-
gem push
|
128
|
+
gem build mvcgen.gemspec
|
129
|
+
gem install mvcgen-0.1.gem
|
130
|
+
gem push mvcgen-0.1.gem
|
133
131
|
```
|
134
132
|
Then you'll be asked for your credentials in order to make the update in the repo (http://guides.rubygems.org/publishing/)
|
135
133
|
|
136
|
-
|
137
|
-
Are you interested in
|
134
|
+
### Add a new template
|
135
|
+
Are you interested in this project and you would like to contribute by adding new templates? Feel free to do it. It's pretty easy. You've just to:
|
138
136
|
- Create a folder inside `templates` with the name of your template
|
139
137
|
- You'll have to create inside the templates a swift folder with your files (get inspired from existing templates)
|
140
138
|
- Use the word MVCGEN where you want the name to be replaced in.
|
141
139
|
- Remember to add the file mvcspec.yml with the description of your template as below:
|
142
140
|
```yaml
|
143
|
-
author:
|
144
|
-
author_email:
|
145
|
-
template_description: Default template with
|
141
|
+
author: pepito
|
142
|
+
author_email: pepito@test.com
|
143
|
+
template_description: Default template with..
|
146
144
|
updated_at: 2018-08-01
|
147
145
|
```
|
148
|
-
- Report it as a PR in this repo updating the gem version in Gemspec.
|
146
|
+
- Report it as a PR in this repo updating the gem version in Gemspec.
|
149
147
|
|
150
148
|
## Resources
|
151
149
|
- Rspec documentation: http://rubydoc.info/gems/rspec-expectations/frames
|
152
150
|
- XCode Plugins: http://nshipster.com/xcode-plugins/
|
153
151
|
- XCodeProj gem (to modify project groups structure): https://github.com/CocoaPods/Xcodeproj
|
154
|
-
- Thor, powerful Ruby library for command line: http://whatisthor.com/
|
152
|
+
- Thor, powerful Ruby library for command line: http://whatisthor.com/
|
data/lib/mvcgen/generator.rb
CHANGED
@@ -18,12 +18,72 @@ module MVCgen
|
|
18
18
|
proj = Xcodeproj::Project.open(project_file)
|
19
19
|
|
20
20
|
# TODO: view this to improve path files: allowable_project_paths
|
21
|
-
self.
|
21
|
+
self.add_files_togroup(proj, proj.main_group, proj.targets.first)
|
22
|
+
# self.addxcodefiles(filespath,proj.main_group,proj.targets.first)
|
22
23
|
|
23
24
|
proj.save
|
24
25
|
puts "Finish adding files"
|
25
26
|
end
|
26
27
|
|
28
|
+
def is_resource_group(file)
|
29
|
+
extname= file[/\.[^\.]+$/]
|
30
|
+
if extname == '.bundle' || extname == '.xcassets' then
|
31
|
+
return true
|
32
|
+
end
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.add_files_togroup(project, group, target)
|
37
|
+
|
38
|
+
if File.exist?(group.real_path)
|
39
|
+
|
40
|
+
Dir.foreach(group.real_path) do |entry|
|
41
|
+
filePath = File.join(group.real_path, entry)
|
42
|
+
|
43
|
+
# puts filePath
|
44
|
+
|
45
|
+
if filePath.to_s.end_with?(".DS_Store", ".xcconfig") then
|
46
|
+
# ignore
|
47
|
+
|
48
|
+
elsif filePath.to_s.end_with?(".lproj") then
|
49
|
+
if @variant_group.nil?
|
50
|
+
@variant_group = group.new_variant_group("Localizable.strings");
|
51
|
+
end
|
52
|
+
string_file = File.join(filePath, "Localizable.strings")
|
53
|
+
fileReference = @variant_group.new_reference(string_file)
|
54
|
+
target.add_resources([fileReference])
|
55
|
+
|
56
|
+
elsif is_resource_group(entry) then
|
57
|
+
fileReference = group.new_reference(filePath)
|
58
|
+
target.add_resources([fileReference])
|
59
|
+
elsif !File.directory?(filePath) then
|
60
|
+
|
61
|
+
fileReference = group.new_reference(filePath)
|
62
|
+
if filePath.to_s.end_with?(".swift", ".mm", ".m", ".cpp") then
|
63
|
+
target.add_file_references([fileReference])
|
64
|
+
elsif filePath.to_s.end_with?(".pch") then
|
65
|
+
|
66
|
+
elsif filePath.to_s.end_with?("Info.plist") && entry == "Info.plist" then
|
67
|
+
|
68
|
+
elsif filePath.to_s.end_with?(".h") then
|
69
|
+
# target.headers_build_phase.add_file_reference(fileReference)
|
70
|
+
elsif filePath.to_s.end_with?(".framework") || filePath.to_s.end_with?(".a") then
|
71
|
+
target.frameworks_build_phases.add_file_reference(fileReference)
|
72
|
+
elsif
|
73
|
+
target.add_resources([fileReference])
|
74
|
+
end
|
75
|
+
elsif File.directory?(filePath) && entry != '.' && entry != '..' then
|
76
|
+
|
77
|
+
subGroup = group.find_subpath(entry, true)
|
78
|
+
subGroup.set_source_tree(group.source_tree)
|
79
|
+
subGroup.set_path(File.join(group.real_path, entry))
|
80
|
+
add_files_togroup(project, target, subGroup)
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
27
87
|
def self.addxcodefiles(direc, current_group, main_target)
|
28
88
|
Dir.glob(direc) do |item|
|
29
89
|
next if item == '.' or item == '.DS_Store'
|
data/lib/mvcgen/version.rb
CHANGED
@@ -13,11 +13,11 @@ import UIKit
|
|
13
13
|
protocol ForgetPasswordVCDelegate: class {
|
14
14
|
func removeBlurredBackgroundView()
|
15
15
|
}
|
16
|
+
|
16
17
|
class ForgetPasswordVC: UIViewController, UIGestureRecognizerDelegate {
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
// MARK: - Outlets
|
20
|
+
|
21
21
|
@IBOutlet weak var cancelButton: UIButton!
|
22
22
|
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
|
23
23
|
@IBOutlet weak var topConstraint: NSLayoutConstraint!
|
@@ -25,7 +25,14 @@ class ForgetPasswordVC: UIViewController, UIGestureRecognizerDelegate {
|
|
25
25
|
@IBOutlet weak var recoverView: UIView!
|
26
26
|
@IBOutlet weak var emailTextField: UITextField!
|
27
27
|
@IBOutlet weak var sendButton: LoadingButton!
|
28
|
+
|
29
|
+
// MARK: - Properties
|
30
|
+
|
31
|
+
weak var delegate: ForgetPasswordVCDelegate?
|
32
|
+
private var keyboardIsShowing: Bool = false
|
28
33
|
|
34
|
+
// MARK: - Life cycle
|
35
|
+
|
29
36
|
override func viewDidLoad() {
|
30
37
|
super.viewDidLoad()
|
31
38
|
|
@@ -39,21 +46,26 @@ class ForgetPasswordVC: UIViewController, UIGestureRecognizerDelegate {
|
|
39
46
|
|
40
47
|
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWasShown), name: .UIKeyboardWillShow, object: nil);
|
41
48
|
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWasHidden), name: .UIKeyboardWillHide, object: nil);
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
override func viewDidLayoutSubviews() {
|
53
|
+
view.backgroundColor = UIColor.clear
|
42
54
|
|
43
|
-
|
55
|
+
//ensure that the icon embeded in the cancel button fits in nicely
|
56
|
+
cancelButton.imageView?.contentMode = .scaleAspectFit
|
44
57
|
}
|
45
58
|
|
59
|
+
// MARK: - UIGestureRecognizerDelegate
|
60
|
+
|
46
61
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if touch.view?.restorationIdentifier == "backViewID" {
|
51
|
-
return true
|
52
|
-
}
|
53
|
-
return false
|
62
|
+
|
63
|
+
let result = (keyboardIsShowing || touch.view?.restorationIdentifier != "backViewID") ? false : true
|
64
|
+
return result
|
54
65
|
}
|
55
66
|
|
56
67
|
@objc func dismissView(){
|
68
|
+
|
57
69
|
dismiss(animated: true, completion: nil)
|
58
70
|
delegate?.removeBlurredBackgroundView()
|
59
71
|
}
|
@@ -61,7 +73,7 @@ class ForgetPasswordVC: UIViewController, UIGestureRecognizerDelegate {
|
|
61
73
|
|
62
74
|
@objc func keyboardWasShown(notification: NSNotification) {
|
63
75
|
|
64
|
-
self.
|
76
|
+
self.keyboardIsShowing = true
|
65
77
|
|
66
78
|
UIView.animate(withDuration: 0.5, animations: { () -> Void in
|
67
79
|
self.bottomConstraint.constant = 287
|
@@ -71,7 +83,7 @@ class ForgetPasswordVC: UIViewController, UIGestureRecognizerDelegate {
|
|
71
83
|
|
72
84
|
@objc func keyboardWasHidden(notification: NSNotification) {
|
73
85
|
|
74
|
-
self.
|
86
|
+
self.keyboardIsShowing = false
|
75
87
|
|
76
88
|
UIView.animate(withDuration: 0.5, animations: { () -> Void in
|
77
89
|
self.topConstraint.constant = 148.5
|
@@ -79,47 +91,28 @@ class ForgetPasswordVC: UIViewController, UIGestureRecognizerDelegate {
|
|
79
91
|
})
|
80
92
|
}
|
81
93
|
|
82
|
-
override func viewDidLayoutSubviews() {
|
83
|
-
view.backgroundColor = UIColor.clear
|
84
|
-
|
85
|
-
//ensure that the icon embeded in the cancel button fits in nicely
|
86
|
-
cancelButton.imageView?.contentMode = .scaleAspectFit
|
87
|
-
|
88
|
-
//add a white tint color for the Cancel button image
|
89
|
-
// let cancelImage = UIImage(named: "Cancel")
|
90
|
-
|
91
|
-
// let tintedCancelImage = cancelImage?.withRenderingMode(.alwaysTemplate)
|
92
|
-
// cancelButton.setImage(tintedCancelImage, for: .normal)
|
93
|
-
// cancelButton.tintColor = .white
|
94
|
-
}
|
95
|
-
|
96
94
|
// MARK: - Actions
|
95
|
+
|
97
96
|
@IBAction func cancelTapped(_ sender: UIButton) {
|
97
|
+
|
98
98
|
self.dismissView()
|
99
99
|
}
|
100
100
|
|
101
101
|
@IBAction func sendTapped(_ sender: UIButton) {
|
102
|
-
|
102
|
+
|
103
|
+
if self.emailTextField.isEmail() {
|
104
|
+
if let email = self.emailTextField.text {
|
103
105
|
self.sendButton.showLoading()
|
104
106
|
APIManager.sharedInstance.forgotPwd(withParameters: APIRequestBody.forgotPwd(withEmail: email), completion: {
|
105
107
|
result in
|
106
108
|
self.sendButton.hideLoading()
|
107
109
|
if result == .success {
|
108
|
-
APIHelper.sharedInstance.showSuccesMessage(with:
|
110
|
+
APIHelper.sharedInstance.showSuccesMessage(with: "Email sent!", and: "")
|
109
111
|
}
|
110
112
|
})
|
111
113
|
} else {
|
112
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
114
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Invalid email", and: "")
|
113
115
|
}
|
114
116
|
}
|
115
117
|
|
116
|
-
// MARK: - Private
|
117
|
-
|
118
|
-
private func isValidEmail(_ testStr:String) -> Bool {
|
119
|
-
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
|
120
|
-
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
|
121
|
-
return emailTest.evaluate(with: testStr)
|
122
|
-
}
|
123
|
-
|
124
|
-
|
125
118
|
}
|
@@ -23,8 +23,6 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
|
26
|
-
private let homeStoryboard = UIStoryboard(name: "Home", bundle: Bundle.main)
|
27
|
-
|
28
26
|
@IBOutlet weak var registerButton: UIButton!{
|
29
27
|
didSet{
|
30
28
|
registerButton.addShadow()
|
@@ -37,14 +35,18 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
37
35
|
}
|
38
36
|
}
|
39
37
|
|
38
|
+
// MARK: - Properties
|
39
|
+
|
40
|
+
private static let homeStoryboard = UIStoryboard(name: "Home", bundle: Bundle.main)
|
41
|
+
|
40
42
|
private var pastelView: PastelView!
|
41
43
|
|
44
|
+
// MARK: - Life cycle
|
45
|
+
|
42
46
|
override func viewDidLoad() {
|
43
47
|
super.viewDidLoad()
|
44
48
|
|
45
|
-
|
46
|
-
self.emailTextField.delegate = self
|
47
|
-
self.passwordTextField.delegate = self
|
49
|
+
setupTextFieldsDelegate()
|
48
50
|
|
49
51
|
configureText()
|
50
52
|
|
@@ -95,12 +97,14 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
95
97
|
}
|
96
98
|
|
97
99
|
@IBAction func forgetPasswordTapped(_ sender: UIButton) {
|
100
|
+
|
98
101
|
self.definesPresentationContext = true
|
99
102
|
self.providesPresentationContextTransitionStyle = true
|
100
|
-
|
101
103
|
self.overlayBlurredBackgroundView()
|
102
104
|
}
|
103
105
|
|
106
|
+
// MARK: - Navigation
|
107
|
+
|
104
108
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
105
109
|
if let identifier = segue.identifier {
|
106
110
|
if identifier == "ShowForgetPassword" {
|
@@ -113,6 +117,7 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
113
117
|
}
|
114
118
|
|
115
119
|
// MARK: - UITextFieldDelegate
|
120
|
+
|
116
121
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
117
122
|
|
118
123
|
if textField.tag == 1 {
|
@@ -136,6 +141,12 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
136
141
|
|
137
142
|
// MARK: - Private
|
138
143
|
|
144
|
+
private func setupTextFieldsDelegate(){
|
145
|
+
|
146
|
+
self.emailTextField.delegate = self
|
147
|
+
self.passwordTextField.delegate = self
|
148
|
+
}
|
149
|
+
|
139
150
|
private func configureText(){
|
140
151
|
|
141
152
|
self.emailTextField.attributedPlaceholder = NSAttributedString(string: NSLocalizedString("Email", comment: ""),
|
@@ -193,7 +204,7 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
193
204
|
|
194
205
|
private func validateForm() -> Bool {
|
195
206
|
|
196
|
-
if self.emailTextField.
|
207
|
+
if !self.emailTextField.isEmail() {
|
197
208
|
errorOnLogin(causeOfFailure: "email")
|
198
209
|
return false
|
199
210
|
}
|
@@ -210,13 +221,13 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
210
221
|
|
211
222
|
switch error {
|
212
223
|
case "email":
|
213
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
224
|
+
APIHelper.sharedInstance.showErrorMessage(with: "You must enter an email", and: "")
|
214
225
|
break
|
215
226
|
case "password":
|
216
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
227
|
+
APIHelper.sharedInstance.showErrorMessage(with: "You must enter a password", and: "")
|
217
228
|
break
|
218
229
|
default:
|
219
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
230
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Check the entered data", and: "")
|
220
231
|
break
|
221
232
|
}
|
222
233
|
|
@@ -230,7 +241,6 @@ class LoginVC: UITableViewController, UITextFieldDelegate, ForgetPasswordVCDeleg
|
|
230
241
|
blurredBackgroundView.effect = UIBlurEffect(style: .dark)
|
231
242
|
|
232
243
|
self.tableView.addSubview(blurredBackgroundView)
|
233
|
-
|
234
244
|
}
|
235
245
|
|
236
246
|
@objc func removeBlurredBackgroundView() {
|
@@ -11,6 +11,8 @@ import Pastel
|
|
11
11
|
|
12
12
|
class RegisterVC: UITableViewController, UITextFieldDelegate {
|
13
13
|
|
14
|
+
// MARK: - Outlets
|
15
|
+
|
14
16
|
@IBOutlet weak var nameTextField: UITextField!
|
15
17
|
@IBOutlet weak var lastnameTextField: UITextField!
|
16
18
|
@IBOutlet weak var cellphoneTextField: UITextField!
|
@@ -24,19 +26,18 @@ class RegisterVC: UITableViewController, UITextFieldDelegate {
|
|
24
26
|
}
|
25
27
|
@IBOutlet weak var acceptTermsButton: UIButton!
|
26
28
|
|
29
|
+
// MARK: - Properties
|
30
|
+
|
27
31
|
private var pastelView: PastelView!
|
28
32
|
|
29
33
|
private var termsAndConditionsAccepted: Bool = false
|
30
34
|
|
35
|
+
// MARK: - Life cycle
|
36
|
+
|
31
37
|
override func viewDidLoad() {
|
32
38
|
super.viewDidLoad()
|
33
39
|
|
34
|
-
|
35
|
-
self.lastnameTextField.delegate = self
|
36
|
-
self.cellphoneTextField.delegate = self
|
37
|
-
self.emailTextField.delegate = self
|
38
|
-
self.passwordTextField.delegate = self
|
39
|
-
self.confirmPasswordTextField.delegate = self
|
40
|
+
setupTextFieldsDelegate()
|
40
41
|
|
41
42
|
configureText()
|
42
43
|
|
@@ -52,8 +53,8 @@ class RegisterVC: UITableViewController, UITextFieldDelegate {
|
|
52
53
|
self.pastelView.startAnimation()
|
53
54
|
}
|
54
55
|
|
55
|
-
|
56
56
|
// MARK: - UITextFieldDelegate
|
57
|
+
|
57
58
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
58
59
|
|
59
60
|
let nextTage = textField.tag+1
|
@@ -72,6 +73,7 @@ class RegisterVC: UITableViewController, UITextFieldDelegate {
|
|
72
73
|
// MARK: - Actions
|
73
74
|
|
74
75
|
@IBAction func createTapped(_ sender: UIButton) {
|
76
|
+
|
75
77
|
if self.validateForm(){
|
76
78
|
if let email = self.emailTextField.text, let password = self.passwordTextField.text, let name = self.nameTextField.text, let lastname = self.lastnameTextField.text, let cellphone = self.cellphoneTextField.text {
|
77
79
|
self.createAccountButton.showLoading()
|
@@ -94,6 +96,7 @@ class RegisterVC: UITableViewController, UITextFieldDelegate {
|
|
94
96
|
}
|
95
97
|
|
96
98
|
@IBAction func termsTapped(_ sender: UIButton) {
|
99
|
+
|
97
100
|
if !termsAndConditionsAccepted {
|
98
101
|
let tintedImage = Asset.tick.image.withRenderingMode(.alwaysTemplate)
|
99
102
|
sender.setImage(tintedImage, for: .normal)
|
@@ -109,44 +112,70 @@ class RegisterVC: UITableViewController, UITextFieldDelegate {
|
|
109
112
|
}
|
110
113
|
|
111
114
|
@IBAction func termsAndConditionsTapped(_ sender: UIButton) {
|
112
|
-
// TODO:
|
113
|
-
if let url = URL(string: "
|
115
|
+
// TODO: URL
|
116
|
+
if let url = URL(string: "/terms-and-conditions") {
|
114
117
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
115
118
|
}
|
116
119
|
}
|
117
120
|
|
118
121
|
@IBAction func alreadyHaveAccountTapped(_ sender: UIButton) {
|
122
|
+
|
119
123
|
self.dismiss(animated: true, completion: nil)
|
120
124
|
}
|
121
125
|
|
122
|
-
|
123
|
-
|
124
126
|
// MARK: - Private
|
127
|
+
|
128
|
+
private func setupTextFieldsDelegate(){
|
129
|
+
|
130
|
+
self.nameTextField.delegate = self
|
131
|
+
self.lastnameTextField.delegate = self
|
132
|
+
self.cellphoneTextField.delegate = self
|
133
|
+
self.emailTextField.delegate = self
|
134
|
+
self.passwordTextField.delegate = self
|
135
|
+
self.confirmPasswordTextField.delegate = self
|
136
|
+
}
|
125
137
|
|
126
138
|
private func configureText(){
|
127
139
|
|
128
|
-
self.emailTextField.attributedPlaceholder = NSAttributedString(string:
|
129
|
-
attributes: [
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
self.
|
135
|
-
attributes: [
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
self.
|
141
|
-
attributes: [
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
140
|
+
self.emailTextField.attributedPlaceholder = NSAttributedString(string: "Email",
|
141
|
+
attributes: [
|
142
|
+
NSAttributedStringKey.foregroundColor: UIColor.lightGray,
|
143
|
+
NSAttributedStringKey.font: Fonts.roboto(type: 1, fontSize: 17)
|
144
|
+
])
|
145
|
+
|
146
|
+
self.nameTextField.attributedPlaceholder = NSAttributedString(string: "Name",
|
147
|
+
attributes: [
|
148
|
+
NSAttributedStringKey.foregroundColor: UIColor.lightGray,
|
149
|
+
NSAttributedStringKey.font: Fonts.roboto(type: 1, fontSize: 17)
|
150
|
+
])
|
151
|
+
|
152
|
+
self.lastnameTextField.attributedPlaceholder = NSAttributedString(string: "Lastname",
|
153
|
+
attributes: [
|
154
|
+
NSAttributedStringKey.foregroundColor: UIColor.lightGray,
|
155
|
+
NSAttributedStringKey.font: Fonts.roboto(type: 1, fontSize: 17)
|
156
|
+
])
|
157
|
+
|
158
|
+
self.cellphoneTextField.attributedPlaceholder = NSAttributedString(string: "Cellphone (optional)",
|
159
|
+
attributes: [
|
160
|
+
NSAttributedStringKey.foregroundColor: UIColor.lightGray,
|
161
|
+
NSAttributedStringKey.font: Fonts.roboto(type: 1, fontSize: 17)
|
162
|
+
])
|
163
|
+
|
164
|
+
self.passwordTextField.attributedPlaceholder = NSAttributedString(string: "Password",
|
165
|
+
attributes: [
|
166
|
+
NSAttributedStringKey.foregroundColor: UIColor.lightGray,
|
167
|
+
NSAttributedStringKey.font: Fonts.roboto(type: 1, fontSize: 17)
|
168
|
+
])
|
169
|
+
|
170
|
+
self.confirmPasswordTextField.attributedPlaceholder = NSAttributedString(string: "Confirm password",
|
171
|
+
attributes: [
|
172
|
+
NSAttributedStringKey.foregroundColor: UIColor.lightGray,
|
173
|
+
NSAttributedStringKey.font: Fonts.roboto(type: 1, fontSize: 17)
|
174
|
+
])
|
147
175
|
}
|
148
176
|
|
149
177
|
private func configureViews(){
|
178
|
+
|
150
179
|
self.pastelView = PastelView(frame: self.tableView.bounds)
|
151
180
|
|
152
181
|
// Custom Direction
|
@@ -167,47 +196,28 @@ class RegisterVC: UITableViewController, UITextFieldDelegate {
|
|
167
196
|
|
168
197
|
if let password = self.passwordTextField.text, let confirmPassword = self.confirmPasswordTextField.text {
|
169
198
|
if password != confirmPassword {
|
170
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
199
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Passwords don't match", and: "")
|
171
200
|
return false
|
172
201
|
}
|
173
202
|
}
|
174
|
-
if
|
175
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
203
|
+
if !self.nameTextField.isName() {
|
204
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Check the entered data", and: "")
|
176
205
|
return false
|
177
206
|
}
|
178
|
-
if
|
179
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
207
|
+
if !self.lastnameTextField.isName() {
|
208
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Check the entered data", and: "")
|
180
209
|
return false
|
181
210
|
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
}
|
211
|
+
|
212
|
+
if !self.emailTextField.isEmail(){
|
213
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Invalid email", and: "")
|
214
|
+
return false
|
187
215
|
}
|
188
216
|
if !termsAndConditionsAccepted{
|
189
|
-
APIHelper.sharedInstance.showErrorMessage(with:
|
217
|
+
APIHelper.sharedInstance.showErrorMessage(with: "Check the entered data", and: "You have to accept terms & conditions")
|
190
218
|
return false
|
191
219
|
}
|
192
220
|
return true
|
193
221
|
}
|
194
222
|
|
195
|
-
private func isValidEmail(_ testStr:String) -> Bool {
|
196
|
-
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
|
197
|
-
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
|
198
|
-
return emailTest.evaluate(with: testStr)
|
199
|
-
}
|
200
|
-
|
201
|
-
private func isValidName(_ testStr:String) -> Bool {
|
202
|
-
let nameRegEx = "[A-Za-z\\s]+"
|
203
|
-
let nameTest = NSPredicate(format:"SELF MATCHES %@", nameRegEx)
|
204
|
-
return nameTest.evaluate(with: testStr)
|
205
|
-
}
|
206
|
-
|
207
|
-
private func isValidPhone(_ testStr:String) -> Bool {
|
208
|
-
let phoneRegEx = "[0-9]*"
|
209
|
-
let phoneTest = NSPredicate(format:"SELF MATCHES %@", phoneRegEx)
|
210
|
-
return phoneTest.evaluate(with: testStr)
|
211
|
-
}
|
212
|
-
|
213
223
|
}
|