ChandanAppdesk

ResetPasswordVC.swift

Feb 13th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 9.19 KB | Source Code | 0 0
  1. //
  2. // ResetPasswordVC.swift
  3. // hubble-ios
  4. //
  5. // Created by Appdesk Services PVT. LTD. on 13/02/24.
  6. // Copyright (c) 2023 hubble-ios. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ResetPasswordVC: HubbleBaseVC {
  12.  
  13.     // scrolview
  14.     lazy var contentView: UIView = {
  15.         let view = UIView()
  16.         view.isAccessibilityElement = false
  17.         view.backgroundColor = UIColor.colorWith(hexString: "ffffff", alpha: 0.0)
  18.         return view
  19.     }()
  20.  
  21.     lazy var scrollView: UIScrollView = {
  22.         let scroll = UIScrollView()
  23.         scroll.translatesAutoresizingMaskIntoConstraints = false
  24.         scroll.showsVerticalScrollIndicator = true
  25.         scroll.isScrollEnabled = true
  26.         scroll.isAccessibilityElement = false
  27.         scroll.addSubview(contentView)
  28.         contentView.snp.makeConstraints { make in
  29.             make.height.equalTo(700)
  30.             make.top.bottom.left.right.width.equalTo(scroll)
  31.         }
  32.         return scroll
  33.     }()
  34.  
  35.     // navigation bar
  36.     lazy var backButton: UIButton = {
  37.         let button = UIButton()
  38.         button.accessibilityElement(id: AccessIdentifier.backButton, label: AccessLabel.backButton)
  39.         button.backgroundColor = .colorWhiteAlpha1
  40.         button.tintColor = .white
  41.         button.hubbleAction(forControlEvents: .touchUpInside) {
  42.             self.navigationController?.popViewController(animated: true)
  43.         }
  44.         button.corner(cornerRadius: 10)
  45.         button.setImage(.backButton, for: .normal)
  46.         return button
  47.     }()
  48.  
  49.     let titleLabel: UILabel = {
  50.        let label = UILabel()
  51.         label.font = .fontBold20
  52.         label.text = "Reset Password"
  53.         return label
  54.     }()
  55.  
  56.     // page Content
  57.     lazy var appIcon: UIImageView = {
  58.         let imageView = UIImageView()
  59.         imageView.image = .hubbleLogo
  60.         imageView.isAccessibilityElement = false
  61.         return imageView
  62.     }()
  63.     lazy var forgotPasswordLabel: UILabel = {
  64.         let label = UILabel()
  65.         label.text = "Reset\nPassword"
  66.         label.font = .fontBold20
  67.         label.numberOfLines = 2
  68.         label.textColor = .white
  69.         label.textAlignment = .center
  70.         return label
  71.     }()
  72.     lazy var descreptionLabel: UILabel = {
  73.         let label = UILabel()
  74.         label.textColor = .white
  75.         label.font = .fontRegular14
  76.         label.numberOfLines = 2
  77.         label.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
  78.         label.textAlignment = .center
  79.         return label
  80.     }()
  81.    
  82.     lazy var password: (container: UIView, leftImage: UIImageView, fieldTitleLabel: UILabel, textField: UITextField, button: UIButton) = {
  83.         let password = Common.createTextField(leftImage: .lockIcon, placeholder: "signUp_enter_password".myLocalizedString, font: .fontBold16, rightButtonImage: .eyeSlashIcon)
  84.         password.textField.textContentType = .newPassword
  85.         password.button.addTarget(self, action: #selector(passwordTapped), for: .touchUpInside)
  86.         password.textField.isSecureTextEntry = true
  87.         password.fieldTitleLabel.text = "password_text".myLocalizedString
  88.         password.textField.textContentType = .newPassword
  89.         return password
  90.     }()
  91.     lazy var confirmPassword: (container: UIView, leftImage: UIImageView, fieldTitleLabel: UILabel, textField: UITextField, button: UIButton) = {
  92.         let confirmPassword = Common.createTextField(leftImage: .lockIcon, placeholder: "sigUp_enter_confirm_Password".myLocalizedString, font: .fontBold16, rightButtonImage: .eyeSlashIcon)
  93.         confirmPassword.textField.textContentType = .newPassword
  94.         confirmPassword.button.addTarget(self, action: #selector(confirmPasswordTapped), for: .touchUpInside)
  95.         confirmPassword.textField.isSecureTextEntry = true
  96.         confirmPassword.fieldTitleLabel.text = "confirm Password_text".myLocalizedString
  97.         confirmPassword.textField.textContentType = .newPassword
  98.         return confirmPassword
  99.     }()
  100.  
  101.     lazy var submitButton: UIButton = {
  102.         let button = UIButton()
  103.         button.corner(cornerRadius: 12)
  104.         button.setTitle("reviewRating_Submit_text".myLocalizedString, for: .normal)
  105.         button.setTitleColor(.primaryColor, for: .normal)
  106.         button.hubbleAction(forControlEvents: .touchUpInside) {
  107.             self.submitButtonTapped()
  108.         }
  109.         button.titleLabel?.font = .fontBold20
  110.         button.backgroundColor = .white
  111.         return button
  112.     }()
  113.    
  114.     var emailString: String = K.emptyString
  115.    
  116.     override func viewDidLoad() {
  117.         super.viewDidLoad()
  118.         super.isSwipeToBackActive = true
  119.         setupUI()
  120.     }
  121.    
  122.     @objc func passwordTapped() {
  123.         if password.textField.isSecureTextEntry == true {
  124.             password.textField.isSecureTextEntry = false
  125.             password.button.setImage(.eyeIcon, for: .normal)
  126.         } else {
  127.             password.textField.isSecureTextEntry = true
  128.             password.button.setImage(.eyeSlashIcon, for: .normal)
  129.         }
  130.     }
  131.  
  132.     @objc func confirmPasswordTapped() {
  133.         if confirmPassword.textField.isSecureTextEntry == true {
  134.             confirmPassword.textField.isSecureTextEntry = false
  135.             confirmPassword.button.setImage(.eyeIcon, for: .normal)
  136.         } else {
  137.             confirmPassword.textField.isSecureTextEntry = true
  138.             confirmPassword.button.setImage(.eyeSlashIcon, for: .normal)
  139.         }
  140.     }
  141.  
  142.     func submitButtonTapped() {
  143.         let isValidPassword = password.textField.isValid()
  144.         let isPassAndConfirmPassMatched = confirmPassword.textField.isEqual(text: password.textField.text ?? K.emptyString)
  145.         let isValidStrongPassword = password.textField.validateStrongPassword()
  146.         let isValidConfirmStrongPassword = confirmPassword.textField.validateStrongPassword()
  147.         if isValidPassword && isPassAndConfirmPassMatched && isValidStrongPassword && isValidConfirmStrongPassword {
  148.             password.textField.resignFirstResponder()
  149.             confirmPassword.textField.resignFirstResponder()
  150.         } else {
  151.             if !isValidPassword {
  152.                 showAlert(message: "validation_signUp_password".myLocalizedString)
  153.             } else if !isValidStrongPassword {
  154.                 showAlert(message: "validation_signUp_Strong_password".myLocalizedString)
  155.             } else if !isValidConfirmStrongPassword {
  156.                 showAlert(message: "validation_signUp_confirm_strong_password".myLocalizedString)
  157.             } else if !isPassAndConfirmPassMatched {
  158.                 showAlert(message: "validation_signUp_confirm_password".myLocalizedString)
  159.             }
  160.         }
  161.     }
  162.  
  163.     func setupUI() {
  164.         self.view.addSubview(scrollView)
  165.         scrollView.snp.makeConstraints { make in
  166.             make.top.equalTo(self.view.safeAreaLayoutGuide)
  167.             make.bottom.left.right.equalTo(self.view)
  168.             make.width.equalTo(self.view)
  169.             make.bottom.equalTo(self.view.safeAreaLayoutGuide)
  170.         }
  171.         contentView.addSubview(backButton)
  172.         backButton.snp.makeConstraints { make in
  173.             make.top.equalTo(contentView.snp.top).offset(12)
  174.             make.left.equalTo(contentView.snp.left).offset(20)
  175.             make.height.width.equalTo(40)
  176.         }
  177.         contentView.addSubview(titleLabel)
  178.         titleLabel.snp.makeConstraints { make in
  179.             make.top.equalTo(contentView.snp.top).offset(20)
  180.             make.centerX.equalTo(contentView)
  181.         }
  182.         contentView.addSubview(appIcon)
  183.         appIcon.snp.makeConstraints { make in
  184.             make.centerX.equalTo(contentView)
  185.             make.top.equalTo(titleLabel.bottom).offset(24)
  186.             make.height.equalTo(130)
  187.             make.width.equalTo(124)
  188.         }
  189.         contentView.addSubview(forgotPasswordLabel)
  190.         forgotPasswordLabel.snp.makeConstraints { make in
  191.             make.centerX.equalTo(contentView)
  192.             make.top.equalTo(appIcon.bottom).offset(topOffset)
  193.             make.width.equalTo(contentView)
  194.         }
  195.         contentView.addSubview(descreptionLabel)
  196.         descreptionLabel.snp.makeConstraints { make in
  197.             make.centerX.equalTo(contentView)
  198.             make.top.equalTo(forgotPasswordLabel.bottom).offset(24)
  199.             make.width.equalTo(270)
  200.         }
  201.         contentView.addSubview(password.container)
  202.         password.container.snp.makeConstraints { make in
  203.             make.top.equalTo(descreptionLabel.bottom).offset(44)
  204.             make.left.right.equalTo(contentView)
  205.             make.height.equalTo(Common.containerHeight96)
  206.         }
  207.         contentView.addSubview(confirmPassword.container)
  208.         confirmPassword.container.snp.makeConstraints { make in
  209.             make.top.equalTo(password.container.bottom).offset(topOffset)
  210.             make.left.right.equalTo(contentView)
  211.             make.height.equalTo(Common.containerHeight96)
  212.         }
  213.         contentView.addSubview(submitButton)
  214.         submitButton.snp.makeConstraints { make in
  215.             make.top.equalTo(confirmPassword.container.bottom).offset(24)
  216.             make.left.equalTo(contentView).offset(leftOffset)
  217.             make.right.equalTo(contentView).inset(rightInset)
  218.             make.height.equalTo(64)
  219.         }
  220.     }
  221. }
  222.  
Advertisement
Add Comment
Please, Sign In to add comment