SPasswordChangeViewController.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // SPasswordChangeViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/17.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Eureka
  10. import Alamofire
  11. import AlamofireImage
  12. import AlamofireObjectMapper
  13. import ObjectMapper
  14. import SwiftyJSON
  15. import CocoaLumberjack
  16. class SPasswordChangeViewController: FormViewController {
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "确认", style: .plain, target: self, action: #selector(self.passwordChangeSubmit))
  20. PasswordRow.defaultCellUpdate = {
  21. cell,row in
  22. cell.textLabel?.font = setting_content_textFont
  23. cell.textLabel?.textColor = setting_content_textColor
  24. }
  25. form +++ Section()
  26. <<< PasswordRow("oldPassword"){
  27. $0.title = "原密码"
  28. $0.add(rule: RuleRequired(msg:"请输入原密码"))
  29. $0.validationOptions = .validatesOnDemand
  30. }
  31. +++ Section()
  32. <<< PasswordRow("newPassword"){
  33. $0.title = "新密码"
  34. $0.add(rule: RuleRequired(msg:"请输入新密码"))
  35. $0.validationOptions = .validatesOnDemand
  36. }
  37. <<< PasswordRow("confirmPassword"){
  38. $0.title = "确认新密码"
  39. $0.add(rule: RuleRequired(msg:"请确认新密码"))
  40. $0.validationOptions = .validatesOnDemand
  41. }
  42. }
  43. @objc private func passwordChangeSubmit(){
  44. let oldRow = form.rowBy(tag: "oldPassword") as! PasswordRow
  45. let newRow = form.rowBy(tag: "newPassword") as! PasswordRow
  46. let newConfirmRow = form.rowBy(tag: "confirmPassword") as! PasswordRow
  47. if oldRow.validate().count > 0 {
  48. self.showError(title: oldRow.validate()[0].msg)
  49. //oldRow.cell.becomeFirstResponder()
  50. return
  51. }
  52. if newRow.validate().count > 0 {
  53. self.showError(title: newRow.validate()[0].msg)
  54. //newRow.cell.becomeFirstResponder()
  55. return
  56. }
  57. if newConfirmRow.validate().count > 0 {
  58. self.showError(title: newConfirmRow.validate()[0].msg)
  59. //newConfirmRow.cell.becomeFirstResponder()
  60. return
  61. }
  62. if newRow.value != newConfirmRow.value {
  63. let alert = UIAlertController(title: "提醒", message: "密码修改提示", preferredStyle: .alert)
  64. alert.addAction(UIAlertAction(title: "新密码与确认密码不一致,请修改", style: .default, handler: nil))
  65. self.present(alert, animated: true, completion: nil)
  66. }else{
  67. //生成参数
  68. let parameter = ["oldPassword":oldRow.value!,"newPassword":newRow.value!,"confirmPassword":newConfirmRow.value!]
  69. //修改密码
  70. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(PersonContext.personContextKey, query: PersonContext.personPasswordUpdateQuery, parameter: nil)
  71. self.showLoading(title:"提交中...")
  72. AF.request(url!, method: .put, parameters: parameter, encoding: JSONEncoding.default, headers: nil).responseJSON(completionHandler: { (response) in
  73. switch response.result {
  74. case .success(let val):
  75. let type = JSON(val)["type"]
  76. if type == "success" {
  77. self.showSuccess(title: "修改成功")
  78. }else{
  79. DDLogError(JSON(val).description)
  80. self.showError(title: "修改失败")
  81. }
  82. case .failure(let err):
  83. DDLogError(err.localizedDescription)
  84. self.showError(title: "修改失败")
  85. }
  86. })
  87. }
  88. }
  89. override func didReceiveMemoryWarning() {
  90. super.didReceiveMemoryWarning()
  91. // Dispose of any resources that can be recreated.
  92. }
  93. }