Skip to content

Commit

Permalink
chapter08 重置密码
Browse files Browse the repository at this point in the history
  • Loading branch information
许林 authored and CoderDream committed Dec 5, 2018
1 parent e5eaae4 commit 6dc8373
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 27 deletions.
63 changes: 52 additions & 11 deletions Instagram2018/Instagram2018/Base.lproj/Main.storyboard
Expand Up @@ -58,6 +58,9 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="26"/>
<state key="normal" title="忘记密码?"/>
<connections>
<segue destination="Xwi-mZ-bhP" kind="presentation" id="o6L-9K-Yc3"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down Expand Up @@ -91,45 +94,45 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="密码" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="b5j-7G-UmE">
<rect key="frame" x="8" y="313" width="398" height="36"/>
<rect key="frame" x="8" y="313" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<textInputTraits key="textInputTraits"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="重复密码" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="JHW-RF-vJ1">
<rect key="frame" x="8" y="365" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="电子邮件" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="j2D-VD-LXU">
<rect key="frame" x="8" y="413" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="简介" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="BG5-fs-1Za">
<rect key="frame" x="8" y="542" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="姓名" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="6tb-1s-lCQ">
<rect key="frame" x="8" y="490" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="网站" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="43d-UT-HQc">
<rect key="frame" x="8" y="589" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QWl-nt-qqp">
Expand All @@ -153,10 +156,10 @@
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="用户名" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="feR-XQ-Kso">
<rect key="frame" x="8" y="261" width="398" height="36"/>
<rect key="frame" x="8" y="261" width="398" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
Expand Down Expand Up @@ -190,13 +193,51 @@
<view key="view" contentMode="scaleToFill" id="gEJ-Wl-Ws7">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="xulin.wh@qq.com" borderStyle="roundedRect" placeholder="电子邮件" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="tgh-Xj-Eo4">
<rect key="frame" x="20" y="63" width="374" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ey4-Tx-sID">
<rect key="frame" x="20" y="134" width="150" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.26393219109999999" green="0.34264460679999997" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<state key="normal" title="密码重置">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="resetBtnClick:" destination="Xwi-mZ-bhP" eventType="touchUpInside" id="SpQ-AR-D1o"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eCw-qO-FkF">
<rect key="frame" x="238" y="134" width="150" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<state key="normal" title="取消">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="cancelBtnClick:" destination="Xwi-mZ-bhP" eventType="touchUpInside" id="Mtf-qP-mi7"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="DQq-qr-fX2"/>
</view>
<connections>
<outlet property="cancelBtn" destination="eCw-qO-FkF" id="nMW-Rc-UsD"/>
<outlet property="emailTxt" destination="tgh-Xj-Eo4" id="By7-Ae-EJ5"/>
<outlet property="resetBtn" destination="Ey4-Tx-sID" id="au5-h5-UNA"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="HVY-x3-IMi" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1264" y="24"/>
<point key="canvasLocation" x="1263.768115942029" y="23.64130434782609"/>
</scene>
<!--Item 1-->
<scene sceneID="22k-bF-Aet">
Expand Down
43 changes: 43 additions & 0 deletions Instagram2018/Instagram2018/ResetPasswordViewController.swift
Expand Up @@ -7,9 +7,52 @@
//

import UIKit
import LeanCloud

class ResetPasswordViewController: UIViewController {

@IBOutlet weak var emailTxt: UITextField!
@IBOutlet weak var resetBtn: UIButton!
@IBOutlet weak var cancelBtn: UIButton!


@IBAction func resetBtnClick(_ sender: AnyObject) {
// 隐藏键盘
self.view.endEditing(true)

if emailTxt.text!.isEmpty {
let alert = UIAlertController(title: "请注意", message: "电子邮件不能为空", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}

// 数据存储开发指南 · Swift
// https://leancloud.cn/docs/leanstorage_guide-swift.html#hash1214212664
let result:LCBooleanResult = LCUser.requestPasswordReset(email: emailTxt.text!)

switch result {
case .success:
print("用户重置密码成功")
let alert = UIAlertController(title: "请注意", message: "重置密码连接已经发送到您的电子邮件!", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { (_) in
self.dismiss(animated: true, completion: nil)
})
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
break
case .failure(let error):
print("用户重置密码失败")
print(error.localizedDescription)
break
}

}

@IBAction func cancelBtnClick(_ sender: AnyObject) {
self.dismiss(animated: true, completion: nil)
}

override func viewDidLoad() {
super.viewDidLoad()

Expand Down
28 changes: 13 additions & 15 deletions Instagram2018/Instagram2018/SignUpViewController.swift
Expand Up @@ -95,22 +95,20 @@ class SignUpViewController: UIViewController, UIImagePickerControllerDelegate, U

// 记住登录的用户
// var usernameLC: LCString?
var usernameString: String?
if let usernameLC = user.username {
usernameString = usernameLC.value
print(usernameString)
// 这里只能存储特定的可选类型,不能存LCString类型
UserDefaults.standard.set(usernameString, forKey: "username")
UserDefaults.standard.synchronize()

// 从 AppDelegate 类中调用 login 方法
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
}


// var usernameString: String?
// if let usernameLC = user.username {
// usernameString = usernameLC.value
// // print(usernameString)
// // 这里只能存储特定的可选类型,不能存LCString类型
// UserDefaults.standard.set(usernameString, forKey: "username")
// UserDefaults.standard.synchronize()
//
// // 从 AppDelegate 类中调用 login 方法
// let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
// appDelegate.login()
// }
} else {
print("")
print("用户注册失败")
}
print("result: \(result)")

Expand Down
Expand Up @@ -51,7 +51,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} catch {
}

login()
// login()

return true
}
Expand Down

0 comments on commit 6dc8373

Please sign in to comment.