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