The login logic is modified

dev
wenlei 1 year ago
parent b5a61b0988
commit 858e76cf34

@ -14,6 +14,7 @@
770228E92B55169C00E07F7A /* InternationalNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770228E82B55169C00E07F7A /* InternationalNumber.swift */; };
770228EB2B55174D00E07F7A /* InternationalNumberViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770228EA2B55174D00E07F7A /* InternationalNumberViewModel.swift */; };
770228ED2B55284F00E07F7A /* Login.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770228EC2B55284F00E07F7A /* Login.swift */; };
770228EF2B56142E00E07F7A /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770228EE2B56142E00E07F7A /* User.swift */; };
77165D742B464493002AE0A5 /* BarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77165D732B464493002AE0A5 /* BarButtonItem.swift */; };
7736FF442B4CECF2008D5DAD /* CommentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7736FF432B4CECF2008D5DAD /* CommentViewModel.swift */; };
7736FF462B4CF0E6008D5DAD /* CommentDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7736FF452B4CF0E6008D5DAD /* CommentDetailViewController.swift */; };
@ -214,6 +215,7 @@
770228E82B55169C00E07F7A /* InternationalNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternationalNumber.swift; sourceTree = "<group>"; };
770228EA2B55174D00E07F7A /* InternationalNumberViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternationalNumberViewModel.swift; sourceTree = "<group>"; };
770228EC2B55284F00E07F7A /* Login.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Login.swift; sourceTree = "<group>"; };
770228EE2B56142E00E07F7A /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
77165D732B464493002AE0A5 /* BarButtonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarButtonItem.swift; sourceTree = "<group>"; };
7736FF432B4CECF2008D5DAD /* CommentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentViewModel.swift; sourceTree = "<group>"; };
7736FF452B4CF0E6008D5DAD /* CommentDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentDetailViewController.swift; sourceTree = "<group>"; };
@ -622,6 +624,7 @@
77FA0B352B0C50D800404C5E /* Share.swift */,
77FA0B3D2B0C573600404C5E /* Filter.swift */,
77FA0B532B0F447400404C5E /* Mine.swift */,
770228EE2B56142E00E07F7A /* User.swift */,
7751D3552B42AE4600F1F2BD /* Setting.swift */,
7751D35D2B42B61100F1F2BD /* PersonInfo.swift */,
7751D3712B43B9ED00F1F2BD /* Search.swift */,
@ -1148,6 +1151,7 @@
7751D3802B45271600F1F2BD /* BindPhoneViewModel.swift in Sources */,
774A17F52B045F1C00F56DF1 /* Player.swift in Sources */,
7751D3882B45584000F1F2BD /* LaunchADManager.swift in Sources */,
770228EF2B56142E00E07F7A /* User.swift in Sources */,
7751D37A2B450BB100F1F2BD /* AgreementViewController.swift in Sources */,
778B8AAB2AF8ED0E0034AFD4 /* UIView+Borders.swift in Sources */,
778B8AC12AF8ED280034AFD4 /* TableView.swift in Sources */,

@ -56,7 +56,6 @@ class AlertViewController: UIViewController {
cancelButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
cancelButton.setTitle("取消", for: .normal)
cancelButton.setTitleColor(UIColor.tertiaryText(), for: .normal)
cancelButton.addTarget(AlertViewController.self, action: #selector(cancelButtonClicked), for: .touchUpInside)
return cancelButton
}()
@ -66,13 +65,13 @@ class AlertViewController: UIViewController {
confirmButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
confirmButton.setTitle("确定", for: .normal)
confirmButton.setTitleColor(UIColor.primaryText(), for: .normal)
confirmButton.addTarget(AlertViewController.self, action: #selector(confirmButtonClick), for: .touchUpInside)
return confirmButton
}()
var confirmClosures: (()->())?
var cancelClosures: (()->())?
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
@ -94,6 +93,10 @@ class AlertViewController: UIViewController {
super.viewDidLoad()
makeUI()
cancelButton.addTarget(self, action: #selector(cancelButtonClicked), for: .touchUpInside)
confirmButton.addTarget(self, action: #selector(confirmButtonClick), for: .touchUpInside)
}
@ -158,8 +161,11 @@ class AlertViewController: UIViewController {
}
@objc func cancelButtonClicked() {
if let cancelClosures = self.cancelClosures {
cancelClosures()
self.dismiss(animated: true)
}
}
@objc func confirmButtonClick() {
if let confirmClosures = self.confirmClosures {

@ -63,6 +63,7 @@ class TableViewController: ViewController, UIScrollViewDelegate {
}.disposed(by: rx.disposeBag)
isHeaderLoading.bind(to: self.tableView.rx.endRefresh).disposed(by: rx.disposeBag)
isFooterLoading.bind(to: self.tableView.rx.endRefresh).disposed(by: rx.disposeBag)

@ -116,10 +116,11 @@ class ViewController: UIViewController, Navigatable {
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateUI()
if automaticallyAdjustsLeftBarButtonItem {
adjustLeftBarButtonItem()
}
updateUI()
}
public override func viewDidAppear(_ animated: Bool) {
@ -132,6 +133,8 @@ class ViewController: UIViewController, Navigatable {
deinit {
logDebug("\(type(of: self)): Deinited")
logResourcesCount()
print("\(type(of: self)): Deinited")
}
override public func didReceiveMemoryWarning() {
@ -194,6 +197,8 @@ class ViewController: UIViewController, Navigatable {
self.navigationItem.leftBarButtonItem = backBarButton
} else if self.presentingViewController != nil { // presented
self.navigationItem.leftBarButtonItem = closeBarButton
} else {
self.navigationItem.leftBarButtonItem = nil
}
}

@ -29,18 +29,21 @@ class AuthManager {
var token: Token? {
get {
guard let jsonString = keychain[tokenKey]?.data(using: .utf8),
let token = try? JSONDecoder().decode(Token.self, from: jsonString) else { return nil }
return token
let token = UserDefaults.AccountInfo.string(forKey: .userToken)
return Token.init(isValid: token != nil ? true : false , basicToken: token)
// guard let jsonString = keychain[tokenKey]?.data(using: .utf8),
// let token = try? JSONDecoder().decode(Token.self, from: jsonString) else { return nil }
// return token
}
set {
if let token = newValue,
let data = try? JSONEncoder().encode(token),
let jsonString = String.init(data: data, encoding: .utf8) {
keychain[tokenKey] = jsonString
} else {
keychain[tokenKey] = nil
}
// if let token = newValue,
// let data = try? JSONEncoder().encode(token),
// let jsonString = String.init(data: data, encoding: .utf8) {
// keychain[tokenKey] = jsonString
// } else {
// keychain[tokenKey] = nil
// }
UserDefaults.AccountInfo.set(newValue?.basicToken, forKey: .userToken)
tokenChanged.onNext(newValue)
loggedIn.accept(hasValidToken)
}
@ -61,4 +64,6 @@ class AuthManager {
class func tokenValidated() {
AuthManager.shared.token?.isValid = true
}
}

@ -0,0 +1,17 @@
//
// User.swift
// IndieMusic
//
// Created by WenLei on 2024/1/16.
//
import Foundation
struct User: Codable {
let sex: Bool?
let avatar: String?
let nickname: String?
let personality: String?
let id: String?
}

@ -8,6 +8,7 @@
import Foundation
import RxCocoa
import RxSwift
import SVProgressHUD
class HomeTabBarViewModel: ViewModel, ViewModelType {
@ -31,6 +32,13 @@ class HomeTabBarViewModel: ViewModel, ViewModelType {
let tabBarItems = Observable.just([HomeTabBarItem.home, HomeTabBarItem.search, HomeTabBarItem.mine]).asDriver(onErrorJustReturn: [])
if authorized {
renewalToken()
}
return Output(tabBarItems: tabBarItems)
}
@ -47,4 +55,19 @@ class HomeTabBarViewModel: ViewModel, ViewModelType {
return viewModel
}
}
func renewalToken() {
self.provider.autoLogin().subscribe { login in
print("autoLogin: success")
AuthManager.setToken(token: Token.init(isValid: true, basicToken: login.token))
} onFailure: { error in
print("autoLogin: error")
// if case HTTPServiceError.errorJudge(let err) = error {
// SVProgressHUD.showText(withStatus: err.message)
// }
}.disposed(by: rx.disposeBag)
}
}

@ -160,13 +160,23 @@ class HomeViewCell: UITableViewCell {
return commentCountButton
}()
let homeNoLoginView: HomeNoLoginView = {
let homeNoLoginView = HomeNoLoginView.init()
// noLoginBottomView.backgroundColor = .systemBlue
homeNoLoginView.isHidden = true
return homeNoLoginView
}()
var loginClosures: (()->())?
var homeJournal: HomeJournal? {
didSet {
titleLabel.text = homeJournal?.title
subTitleLabel.text = homeJournal?.subTitle
commentLabel.text = homeJournal?.comment
}
}
@ -178,6 +188,8 @@ class HomeViewCell: UITableViewCell {
makeUI()
homeNoLoginView.loginButton.addTarget(self, action: #selector(loginButtonClick), for: .touchUpInside)
titleLabel.text = "标题标题标题标题标题标题"
subTitleLabel.text = "子标题子标题子标题子标题子标题子标题子标题子标题"
commentLabel.text = "评论评论评论评论评论评论评论"
@ -206,6 +218,7 @@ class HomeViewCell: UITableViewCell {
containerView.addSubview(commentLabel)
containerView.addSubview(commentCountButton)
contentView.addSubview(homeNoLoginView)
containerView.snp.makeConstraints { make in
make.left.equalTo(contentView).offset(18)
@ -258,27 +271,23 @@ class HomeViewCell: UITableViewCell {
}
homeNoLoginView.snp.makeConstraints { make in
make.top.equalTo(contentView)
make.left.equalTo(contentView)
make.right.equalTo(contentView)
make.bottom.equalTo(contentView)
}
// override var frame:CGRect{
// didSet {
// let insetX: CGFloat = 18
// let insetY: CGFloat = 0.0
//
// var newFrame = frame
// newFrame.origin.x += insetX
// newFrame.origin.y += insetY
//
// newFrame.size.width -= 2*insetX
// newFrame.size.height -= 2*insetY
//
//
// super.frame = newFrame
// }
// }
//
}
@objc func loginButtonClick() {
if let loginClosures = self.loginClosures {
loginClosures()
}
}
}
@ -446,7 +455,7 @@ class HomeFilterButton: UIControl {
class NoLoginBottomView: UIView {
class HomeNoLoginView: UIView {
var loginButton: UIButton = {
let loginButton = UIButton.init()
loginButton.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
@ -462,9 +471,9 @@ class NoLoginBottomView: UIView {
var gradientLayer: CAGradientLayer = {
let gradientLayer = CAGradientLayer.init()
gradientLayer.colors = [UIColor.init(hex: 0xFFFFFF, alpha: 0).cgColor,
UIColor.init(hex: 0xFFFFFF, alpha: 0.8).cgColor]
gradientLayer.locations = [0.0, 0.9]
gradientLayer.colors = [UIColor.init(hex: 0xF2F3F7, alpha: 0.9).cgColor,
UIColor.init(hex: 0xF3F4F8, alpha: 1).cgColor]
gradientLayer.locations = [0.0, 1]
gradientLayer.startPoint = CGPoint.init(x: 0 , y: 0)
gradientLayer.endPoint = CGPoint.init(x: 0, y: 1)
@ -473,11 +482,11 @@ class NoLoginBottomView: UIView {
}()
override init(frame: CGRect) {
super.init(frame: frame)
makeUI()
}
required init?(coder: NSCoder) {
@ -504,4 +513,6 @@ class NoLoginBottomView: UIView {
make.size.equalTo(CGSize.init(width: 118, height: 32))
}
}
}

@ -28,11 +28,7 @@ class HomeViewController: TableViewController {
var bannerArray = [String]()
let noLoginBottomView: NoLoginBottomView = {
let noLoginBottomView = NoLoginBottomView.init()
// noLoginBottomView.backgroundColor = .systemBlue
return noLoginBottomView
}()
override func viewDidLoad() {
super.viewDidLoad()
@ -44,27 +40,18 @@ class HomeViewController: TableViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// let vm = JournalDetailViewModel.init(provider: viewModel!.provider)
// let vc = JournalDetailController.init(viewModel: vm, navigator: navigator)
//
// self.navigationController?.pushViewController(vc, animated: true)
if let tabbar = self.tabBarController as? HomeTabBarController {
tabbar.showAllBar(true, animated: true)
}
guard let viewModel = viewModel as? HomeViewModel else { return }
self.navigationItem.leftBarButtonItem = nil
// let loginViewModel = LoginViewModel.init(provider: viewModel.provider)
// let login = LoginViewController.init(viewModel: loginViewModel, navigator: navigator)
// self.navigationController?.pushViewController(login, animated: true)
}
override func makeUI() {
super.makeUI()
let headerView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: BaseDimensions.screenWidth, height: 120))
pagerView.frame = headerView.bounds
pagerView.backgroundColor = .red
@ -74,10 +61,8 @@ class HomeViewController: TableViewController {
headerView.addSubview(pagerView)
tableView.tableHeaderView = headerView
tableView.separatorColor = .clear
tableView.register(HomeViewCell.self, forCellReuseIdentifier: "HomeViewCell")
view.addSubview(noLoginBottomView)
}
@ -88,41 +73,40 @@ class HomeViewController: TableViewController {
guard let viewModel = viewModel as? HomeViewModel else { return }
let input = HomeViewModel.Input.init(viewWillAppear: rx.viewWillAppear,
selection: tableView.rx.itemSelected.asDriver(), loginButtonTrigger: self.noLoginBottomView.loginButton.rx.tap.asDriver())
selection: tableView.rx.itemSelected.asDriver())
let output = viewModel.transform(input: input)
let dataSource = HomeViewController.dataSource()
let dataSource = HomeViewController.dataSource { cell, item in
let loginViewModel = LoginViewModel.init(provider: viewModel.provider)
self.navigator.show(segue: .login(viewModel: loginViewModel), sender: self)
}
output.items.bind(to: tableView.rx.items(dataSource: dataSource)).disposed(by: rx.disposeBag)
output.itemSelected.subscribe { [weak self] sectionItem in
switch sectionItem {
default:
let journalDetailViewModel = JournalDetailViewModel.init(provider: viewModel.provider)
self?.navigator.show(segue: .journalDetail(viewModel: journalDetailViewModel), sender: self)
}
}.disposed(by: rx.disposeBag)
isFooterLoading.accept((.loadMore, false))
self.noLoginBottomView.loginButton.rx.tap.subscribe { _ in
let loginViewModel = LoginViewModel.init(provider: viewModel.provider)
self.navigator.show(segue: .login(viewModel: loginViewModel), sender: self)
}.disposed(by: rx.disposeBag)
loggedIn.subscribe { isloggedIn in
if isloggedIn.element == true {
} else {
self.tableView.mj_footer?.rx.refreshFooterState.onNext(RxMJRefreshFooterState.noMoreData)
}
self.tableView.reloadData()
}.disposed(by: rx.disposeBag)
}
@ -130,13 +114,6 @@ class HomeViewController: TableViewController {
super.viewDidLayoutSubviews()
noLoginBottomView.snp.makeConstraints { make in
make.bottom.equalTo(view).offset( -BaseDimensions.tabBarHeight)
make.left.equalTo(view)
make.right.equalTo(view)
make.height.equalTo(100)
}
}
@ -171,7 +148,6 @@ extension HomeViewController: FSPagerViewDataSource {
cell.imageView?.kf.setImage(with: URL.init(string: ""))
cell.imageView?.backgroundColor = .red
return cell
}
@ -180,7 +156,7 @@ extension HomeViewController: FSPagerViewDataSource {
extension HomeViewController {
static func dataSource() -> RxTableViewSectionedReloadDataSource<HomeSectionModel> {
static func dataSource(_ buttonTapHandler: @escaping (UITableViewCell, HomeSectionItem) -> Void) -> RxTableViewSectionedReloadDataSource<HomeSectionModel> {
return RxTableViewSectionedReloadDataSource { dataSource, tableView, indexPath, item in
@ -189,9 +165,17 @@ extension HomeViewController {
let cell: HomeViewCell = tableView.dequeueReusableCell(withIdentifier: "HomeViewCell", for: indexPath) as! HomeViewCell
cell.homeJournal = model
return cell
default: UITableViewCell()
if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
cell.homeNoLoginView.isHidden = AuthManager.shared.token?.isValid ?? false
}
cell.loginClosures = {
buttonTapHandler(cell, item)
}
return cell
}
}
}
@ -219,7 +203,7 @@ extension HomeViewController {
let navigator = self?.navigator else { return }
let filterViewModel = FilterViewModel.init(provider: viewModel.provider)
let filter = FilterViewController.init(viewModel: filterViewModel, navigator: navigator)
// let filter = FilterViewController.init(viewModel: filterViewModel, navigator: navigator)
// self.present(filter, animated: true)
navigator.show(segue: .filter(viewModel: filterViewModel), sender: self, transition: .navigationPresent(type: .filter))
}

@ -14,9 +14,6 @@ class HomeViewModel: ViewModel, ViewModelType {
struct Input {
let viewWillAppear: ControlEvent<Bool>
let selection: Driver<IndexPath>
let loginButtonTrigger: Driver<Void>
}
struct Output {

@ -57,7 +57,6 @@ class AgreementViewController: UIViewController {
cancelButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
cancelButton.setTitle("取消", for: .normal)
cancelButton.setTitleColor(UIColor.tertiaryText(), for: .normal)
cancelButton.addTarget(self, action: #selector(cancelButtonClicked), for: .touchUpInside)
return cancelButton
}()
@ -67,7 +66,7 @@ class AgreementViewController: UIViewController {
confirmButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
confirmButton.setTitle("已阅读并同意", for: .normal)
confirmButton.setTitleColor(UIColor.primaryText(), for: .normal)
confirmButton.addTarget(self, action: #selector(confirmButtonClick), for: .touchUpInside)
// confirmButton.addTarget(self, action: #selector(confirmButtonClick), for: .touchUpInside)
return confirmButton
}()
@ -91,6 +90,9 @@ class AgreementViewController: UIViewController {
super.viewDidLoad()
makeUI()
cancelButton.addTarget(self, action: #selector(cancelButtonClicked), for: .touchUpInside)
}
@ -155,12 +157,12 @@ class AgreementViewController: UIViewController {
}
@objc func cancelButtonClicked() {
self.dismiss(animated: true)
}
@objc func confirmButtonClick() {
}
// @objc func confirmButtonClick() {
//
// }
}

@ -119,9 +119,9 @@ class LoginViewController: ViewController {
}.disposed(by: rx.disposeBag)
self.phoneView.codeButton.rx.tap.subscribe { _ in
self.phoneView.codeButton.rx.tap.subscribe { [weak self] _ in
let internationalNumberViewModel = InternationalNumberViewModel.init(number: viewModel.number, provider: viewModel.provider)
self.navigator.show(segue: .internationalNumber(viewModel: internationalNumberViewModel), sender: self, transition: .modal)
self?.navigator.show(segue: .internationalNumber(viewModel: internationalNumberViewModel), sender: self, transition: .modal)
}.disposed(by: rx.disposeBag)

@ -58,20 +58,25 @@ class PhoneCodeController: ViewController {
return codeButton
}()
let boxInputText = PublishSubject<(String?, Bool)>.init()
let errorLabel: UILabel = {
let errorLabel = UILabel.init()
errorLabel.font = UIFont.systemFont(ofSize: 17, weight: .medium)
errorLabel.textColor = .primary()
return errorLabel
}()
override func viewDidLoad() {
super.viewDidLoad()
boxInputView.textDidChangeblock = { (text, isFinish) in
if isFinish {
let boxInputText = PublishSubject<(String?, Bool)>.init()
}
override func viewDidLoad() {
super.viewDidLoad()
boxInputView.textDidChangeblock = { [weak self] (text, isFinish) in
self.boxInputText.onNext((text, isFinish))
self?.boxInputText.onNext((text, isFinish))
}
}
@ -84,6 +89,7 @@ class PhoneCodeController: ViewController {
view.addSubview(tipsLabel)
view.addSubview(boxInputView)
view.addSubview(codeButton)
view.addSubview(errorLabel)
}
@ -111,7 +117,7 @@ class PhoneCodeController: ViewController {
output.tipsText.drive(self.tipsLabel.rx.text).disposed(by: rx.disposeBag)
output.toAlertView.subscribe { _ in
output.toAlertView.subscribe { [weak self] _ in
let agree = AlertViewController.init()
agree.titleLabel.text = "阅读并同意以下协议"
agree.cancelButton.setTitle("取消", for: .normal)
@ -125,22 +131,17 @@ class PhoneCodeController: ViewController {
(" 并授权获取本机号码", [NSAttributedString.Key.foregroundColor: UIColor.secondaryText(), NSAttributedString.Key.paragraphStyle: paragraphStyle])
])
agree.cancelClosures = {[weak self] in
AuthManager.removeToken()
}
agree.confirmClosures = {[weak self] in
self?.dismiss(animated: true)
self?.navigator.pop(sender: self, toRoot: true)
}
self.present(agree, animated: true)
// self.navigator.pop(sender: self, toRoot: true)
self?.present(agree, animated: true)
}.disposed(by: rx.disposeBag)
}
@ -169,6 +170,12 @@ class PhoneCodeController: ViewController {
make.left.equalTo(view).offset(24)
make.top.equalTo(boxInputView.snp.bottom).offset(24)
}
errorLabel.snp.makeConstraints { make in
make.right.equalTo(view).offset(-24)
make.centerY.equalTo(view)
}
}
}

@ -22,15 +22,13 @@ class PhoneCodeViewModel: ViewModel, ViewModelType {
let isButtonEnabled: Driver<Bool>
let tipsText: Driver<String>
let toAlertView: PublishRelay<Void>
let errorMessage: Driver<String>
}
private var remainingSeconds = 59
private var tipsText = "验证码已发送至 "
// let mobileCheckCode = BehaviorRelay<String>.init(value: "")
let toAlertView = PublishRelay<Void>.init()
var phone: String
@ -43,6 +41,7 @@ class PhoneCodeViewModel: ViewModel, ViewModelType {
func transform(input: Input) -> Output {
let errorMessages = PublishSubject<String>()
let startImmediately = Observable.just(Void())
@ -59,25 +58,7 @@ class PhoneCodeViewModel: ViewModel, ViewModelType {
self?.remainingSeconds = 59
})
// //
// let timer = startCountdown
// .flatMapLatest { _ in
// Observable<Int>.interval(.seconds(1), scheduler
//
//
// let startCountdown = Observable.merge(startImmediately, input.codeButtonTrigger)
// .do(onNext: { [weak self] _ in
// self?.remainingSeconds = 59
// }).flatMapLatest { [weak self] _ -> Observable<Bool> in
// guard let self = self else { return Observable.just(false) }
// return self.requestSMSData()
// }
//
//
//
let timer = startCountdown
.flatMapLatest { _ in
Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
@ -105,19 +86,18 @@ class PhoneCodeViewModel: ViewModel, ViewModelType {
input.boxInputText.subscribe(onNext: { (text, isFinish) in
input.boxInputText.subscribe(onNext: { [weak self] (text, isFinish) in
guard let text = text, isFinish == true else { return }
guard let self = self, let text = text, isFinish == true else { return }
print("text: \(text) isFinish: \(isFinish) ")
self.requestLoginData(mobileCheckCode: text).subscribe(onNext: { login in
UserDefaults.AccountInfo.set(login.token, forKey: .userToken)
UserDefaults.AccountInfo.set(login.id, forKey: .userID)
UserDefaults.AccountInfo.set(login.nickname, forKey: .userName)
self.requestLoginData(mobileCheckCode: text).subscribe(onNext: { [weak self] login in
self.toAlertView.accept(())
AuthManager.setToken(token: Token.init(isValid: true, basicToken: login.token))
// AuthManager.tokenValidated()
self?.toAlertView.accept(())
}, onError: { error in
if case HTTPServiceError.errorJudge(let err) = error {
SVProgressHUD.showText(withStatus: err.message)
@ -131,7 +111,8 @@ class PhoneCodeViewModel: ViewModel, ViewModelType {
return Output(countdownText: countdownText,
isButtonEnabled: isButtonEnabled,
tipsText: tipsText,
toAlertView: toAlertView)
toAlertView: toAlertView,
errorMessage: errorMessages.asDriver(onErrorJustReturn: ""))
}

@ -23,7 +23,6 @@ class MineViewModel: ViewModel, ViewModelType {
let selection: Driver<IndexPath>
let itemSelected: PublishSubject<Mine>
}
let itemSelected = PublishSubject<Mine>()
@ -41,6 +40,15 @@ class MineViewModel: ViewModel, ViewModelType {
items.accept([MineSection.init(items: [single, journal, download])])
requestUserInfoData().subscribe { user in
print(user)
} onError: { error in
}.disposed(by: rx.disposeBag)
input.selection.drive { indexPath in
guard let sectionItem = self.items.value.first?.items[indexPath.row] else { return }
@ -54,4 +62,11 @@ class MineViewModel: ViewModel, ViewModelType {
itemSelected: itemSelected)
}
func requestUserInfoData() -> Observable<User> {
return provider.getUserInfo()
.trackActivity(loading)
.trackError(error)
}
}

@ -19,5 +19,9 @@ protocol IndieMusicAPI {
func sendsms(mobile: String) -> Single<EmptyModel>
///
func loginOrRegister(mobile: String, mobileCheckCode: String) -> Single<Login>
/// Token
func autoLogin() -> Single<Login>
///
func getUserInfo() -> Single<User>
}

@ -18,8 +18,9 @@ protocol ProductAPIType {
enum APIConfig {
case wechatAccessToken([String: Any])
case login(String, String, [String: Any])
case sendsms(mobil: String, [String: Any])
case autoLogin([String: Any])
case getUserInfo([String: Any])
}
extension APIConfig: TargetType {
@ -33,6 +34,10 @@ extension APIConfig: TargetType {
case .sendsms(let mobil, _):
return "user/user/sendsms/\(mobil)"
case .autoLogin:
return "user/user/autoLogin"
case .getUserInfo:
return "user/my/getUserInfo"
}
}
@ -40,7 +45,7 @@ extension APIConfig: TargetType {
switch self {
case .wechatAccessToken:
return .get
case .sendsms, .login:
case .sendsms, .login, .autoLogin, .getUserInfo:
return .post
}
}
@ -52,7 +57,7 @@ extension APIConfig: TargetType {
case .login:
return JSONEncoding.default
case .sendsms:
case .sendsms, .autoLogin, .getUserInfo:
return JSONEncoding.default
}
}
@ -64,7 +69,7 @@ extension APIConfig: TargetType {
case .wechatAccessToken:
return .requestPlain
case .login(_, _, let dic), .sendsms(_, let dic):
case .login(_, _, let dic), .sendsms(_, let dic), .autoLogin(let dic), .getUserInfo(let dic):
parameters = dic
return .requestParameters(parameters: parameters, encoding: parameterEncoding)
@ -78,7 +83,7 @@ extension APIConfig: TargetType {
switch self {
case .wechatAccessToken:
return URL(string: Configs.App.wechatURL)!
case .login, .sendsms:
case .login, .sendsms, .autoLogin, .getUserInfo:
return URL(string: Configs.App.environmentType.baseUrl)!
}
@ -86,9 +91,8 @@ extension APIConfig: TargetType {
var headers : [String : String]? {
switch self {
case .wechatAccessToken:
return nil
case .autoLogin, .getUserInfo:
return ["token": AuthManager.shared.token?.basicToken ?? ""]
default:
return nil
}

@ -72,18 +72,22 @@ extension RestApi {
return requestObject(.wechatAccessToken(dic), with: "data", type: EmptyModel.self)
}
func loginOrRegister(mobile: String, mobileCheckCode: String) -> Single<Login> {
return requestObject(.login(mobile, mobileCheckCode, ["": ""]), with: "data", type: Login.self)
}
func autoLogin() -> Single<Login> {
return requestObject(.autoLogin(["": ""]), with: "data", type: Login.self)
}
func sendsms(mobile: String) -> Single<EmptyModel> {
let dic = ["": ""]
return requestObject(.sendsms(mobil: mobile, dic), with: "data", type: EmptyModel.self)
}
func getUserInfo() -> Single<User> {
let dic = ["": ""]
return requestObject(.getUserInfo(dic), with: "data", type: User.self)
}

Loading…
Cancel
Save