Browse Source

release version 2.4.0

pull/1/head
InKwon James Kim 5 years ago
parent
commit
61af6df08f
  1. 29
      GMERemittance/Module/ForgotPassword/Application Logic/Interactor/ForgotPasswordInteractor.swift
  2. 3
      GMERemittance/Module/ForgotPassword/User Interface/View/ForgotPasswordViewController.swift
  3. 5
      GMERemittance/Module/Home/User Interface/Wireframe/HomeWireframe.swift
  4. 109
      GMERemittance/Module/Login/Application Logic/Interactor/LoginInteractor.swift
  5. 2
      GMERemittance/Module/Login/Application Logic/Interactor/LoginInteractorIO.swift
  6. 2
      GMERemittance/Module/Login/Module Interface/LoginModuleInterface.swift
  7. 4
      GMERemittance/Module/Login/User Interface/Presenter/LoginPresenter.swift
  8. 4
      GMERemittance/Module/Login/User Interface/View/Login.storyboard
  9. 55
      GMERemittance/Module/Login/User Interface/View/LoginViewController.swift

29
GMERemittance/Module/ForgotPassword/Application Logic/Interactor/ForgotPasswordInteractor.swift

@ -21,30 +21,6 @@ class ForgotPasswordInteractor {
self.service = service
}
private func isValid(userName: String, dob: String) -> (isValid: Bool, error: Error){
var error = ""
var isValid = true
if userName.contains("@") {
if !Utility.isValidEmail(email: userName) {error = error + "email_valid_error".localized()
isValid = false
}
}else {
isValid = true
if ( userName.rangeOfCharacter(from: NSCharacterSet.letters) != nil) {
error = error + "email_valid_error".localized()
isValid = false
}
}
// if userName.isEmpty {
// error = error + "email_valid_error".localized();
// isValid = false
// }
let _error = NSError.init(domain: "ForgotPasswordInteractor", code: 0, userInfo: [NSLocalizedDescriptionKey : error])
return (isValid, _error)
}
// MARK: Converting entities
}
@ -52,11 +28,6 @@ class ForgotPasswordInteractor {
extension ForgotPasswordInteractor: ForgotPasswordInteractorInput {
func reset(username: String, dob: String) {
let result = self.isValid(userName: username, dob: dob)
if !result.isValid {
self.output?.show(error: result.error)
return
}
self.service.reset(username: username, dob: dob, success: { (message) in
self.output?.show(message: message)
KeyChain.shared.removeAll()

3
GMERemittance/Module/ForgotPassword/User Interface/View/ForgotPasswordViewController.swift

@ -59,6 +59,8 @@ class ForgotPasswordViewController: UIViewController {
userNameTextField.statusImageView.isHidden = true
userNameTextField.validCondition = {
self.userNameTextField.filterForUserIDFormat()
if $0.count > 3 {
self.isValid = true
return self.isValid
@ -75,6 +77,7 @@ class ForgotPasswordViewController: UIViewController {
userNameTextField.titleFont = font
userNameTextField.placeholder = StringConstants().userIdPlaceholder
userNameTextField.titleText = StringConstants().userIdTitleText
userNameTextField.errorMessage = "userid_error_text".localized()
resetButton.setTitle(StringConstants().resetText, for: UIControl.State.normal)

5
GMERemittance/Module/Home/User Interface/Wireframe/HomeWireframe.swift

@ -71,7 +71,10 @@ extension HomeWireframe: HomeWireframeInput {
}
func showPennyTestSubmit() {
PennyTestSubmitWireframe().openMainView(source: view)
let vc = PennyTestSubmitWireframe().getMainView()
let navigationVC = UINavigationController(rootViewController: vc)
view.present(navigationVC, animated: true, completion: nil)
// self.pennyTestSubmitWireFrame.openPennyTestSubmit(with: view)
}

109
GMERemittance/Module/Login/Application Logic/Interactor/LoginInteractor.swift

@ -9,82 +9,51 @@
import Foundation
class LoginInteractor {
// MARK: Properties
weak var output: LoginInteractorOutput?
private let service: LoginServiceType
// MARK: Initialization
init(service: LoginServiceType) {
self.service = service
}
func toBase64(text: String) -> String? {
guard let data = text.data(using: String.Encoding.utf8) else {
return nil
}
return data.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
// MARK: Properties
weak var output: LoginInteractorOutput?
private let service: LoginServiceType
// MARK: Initialization
init(service: LoginServiceType) {
self.service = service
}
func toBase64(text: String) -> String? {
guard let data = text.data(using: String.Encoding.utf8) else {
return nil
}
private func isValid(userName: String, password: String) -> (isValid: Bool, error: Error){
var error = ""
var isValid = true
if userName.isEmpty {
error = error + "\n" + "email_valid_error".localized();
isValid = false
}
if password.isEmpty {error = error + "\n" + "password_empty_error".localized();
isValid = false
}
let _error = NSError.init(domain: "LoginInteractor", code: 0, userInfo: [NSLocalizedDescriptionKey : error])
return (isValid, _error)
}
// MARK: Converting entities
return data.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
}
// MARK: Converting entities
}
// MARK: Login interactor input interface
extension LoginInteractor: LoginInteractorInput {
func login(userName: String, password: String, encryptedPassword: String) {
let username = userName
let validationResult = self.isValid(userName: username, password: encryptedPassword)
if !validationResult.isValid {
self.output?.show(error: validationResult.error)
return
}
guard let passwordBase64Data = self.toBase64(text: password) else {
return
}
print("password converted is")
print(passwordBase64Data)
// send encrypted password to server for kftc
self.service._login(userId: username, password: encryptedPassword, success: { (user) in
let accessCode = user?.accessCode ?? ""
let accessCodeBase64 = accessCode
Utility.save(user: user, accessCodeBase64: accessCodeBase64, password: encryptedPassword, login: true)
self.output?.loggedIn()
}) { (error) in
self.output?.show(error: error)
guard
let storedEmail = KeyChain.shared.get(key: .id),
storedEmail == username else {
return
}
KeyChain.shared.removeAll()
}
func login(userName: String, encryptedPassword: String) {
// send encrypted password to server for kftc
self.service._login(userId: userName, password: encryptedPassword, success: { (user) in
let accessCode = user?.accessCode ?? ""
let accessCodeBase64 = accessCode
Utility.save(user: user, accessCodeBase64: accessCodeBase64, password: encryptedPassword, login: true)
self.output?.loggedIn()
}) { (error) in
self.output?.show(error: error)
guard
let storedEmail = KeyChain.shared.get(key: .id),
storedEmail == userName else {
return
}
KeyChain.shared.removeAll()
}
}
}

2
GMERemittance/Module/Login/Application Logic/Interactor/LoginInteractorIO.swift

@ -7,7 +7,7 @@
//
protocol LoginInteractorInput: class {
func login(userName: String, password: String, encryptedPassword: String)
func login(userName: String, encryptedPassword: String)
}
protocol LoginInteractorOutput: class {

2
GMERemittance/Module/Login/Module Interface/LoginModuleInterface.swift

@ -7,7 +7,7 @@
//
protocol LoginModuleInterface: class {
func login(userName: String, password: String, encryptedPassword: String)
func login(userName: String, encryptedPassword: String)
func register()
func forgotPassword()
}

4
GMERemittance/Module/Login/User Interface/Presenter/LoginPresenter.swift

@ -22,9 +22,9 @@ class LoginPresenter {
// MARK: Login module interface
extension LoginPresenter: LoginModuleInterface {
func login(userName: String, password: String, encryptedPassword: String) {
func login(userName: String, encryptedPassword: String) {
self.view?.showLoading()
self.interactor?.login(userName: userName, password: password, encryptedPassword: encryptedPassword)
self.interactor?.login(userName: userName, encryptedPassword: encryptedPassword)
}
func register() {

4
GMERemittance/Module/Login/User Interface/View/Login.storyboard

@ -86,9 +86,9 @@
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="150" id="lwa-cj-w5H"/>
</constraints>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7fh-7w-AcM">
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7fh-7w-AcM">
<rect key="frame" x="30" y="587" width="315" height="50"/>
<color key="backgroundColor" red="0.92941176469999998" green="0.10980392160000001" blue="0.14117647059999999" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="Lcl-2a-6hA"/>
</constraints>

55
GMERemittance/Module/Login/User Interface/View/LoginViewController.swift

@ -56,6 +56,17 @@ class LoginViewController: UIViewController {
var presenter: LoginModuleInterface?
private var validDic = [
"id": false,
"pw": false
]
private var isValid = false {
didSet{
loginButton.isEnabled = isValid
loginButton.backgroundColor = isValid ? AppConstants.themeRedColor : .lightGray
}
}
// MARK: VC's Life cycle
@ -89,8 +100,7 @@ class LoginViewController: UIViewController {
@IBAction func login(_ sender: UIButton) {
let username = self.userNameTextField.text!
let password = self.passwordTextField.text!
self.presenter?.login(userName: username, password: password, encryptedPassword: self.encryptedPassword ?? "")
self.presenter?.login(userName: username, encryptedPassword: self.encryptedPassword ?? "")
}
// MARK: Other Functions
@ -107,43 +117,29 @@ class LoginViewController: UIViewController {
userNameTextField.statusImageView.isHidden = true
userNameTextField.validCondition = { $0.count > 3 }
userNameTextField.errorMessage = "userid_error_text".localized()
userNameTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
passwordTextField.titleFont = font
passwordTextField.statusImageView.isHidden = true
passwordTextField.validCondition = { $0.count > 5 }
passwordTextField.errorMessage = "password_policy_error".localized()
passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
loginButton.layer.cornerRadius = 10
}
func authenticateUser() {
let context : LAContext = LAContext()
var error: NSError?
let reasonString = "Authentication is needed to access Gme Remit application."
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) {
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString) { (success, error) in
if success {
print("authenticated")
}
else {
// print(evalPolicyError?.localizedDescription)
guard let error = error as NSError? else {return}
switch error.code {
case LAError.systemCancel.rawValue:
print("Authentication was cancell by the system")
case LAError.userCancel.rawValue:
print("Authentication cancelled by the user")
case LAError.userFallback.rawValue:
print("user selected to enter custome password")
default:
print("Authentication failed.")
}
}
}
@objc private func editingChanged(_ textField: ValidationTextField) {
switch textField {
case userNameTextField:
userNameTextField.filterForUserIDFormat()
validDic["id"] = userNameTextField.isValid
case passwordTextField:
validDic["pw"] = passwordTextField.isValid
default: ()
}
isValid = validDic.reduce(true){ $0 && $1.value}
}
private func configureLanguage() {
@ -166,7 +162,6 @@ class LoginViewController: UIViewController {
}
func setupColor() {
self.loginButton.backgroundColor = AppConstants.themeRedColor
self.headerTitle.textColor = AppConstants.themeRedColor
}

Loading…
Cancel
Save