Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logout option full reset #1107

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions App/Main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
if ForumsClient.shared.isLoggedIn {
setRootViewController(rootViewControllerStack.rootViewController, animated: false, completion: nil)
} else {
if loginViewController == nil {
newLoginController()
}
setRootViewController(loginViewController.enclosingNavigationController, animated: false, completion: nil)
}

Expand Down Expand Up @@ -121,13 +124,13 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func applicationWillResignActive(_ application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning here and with DidBecomeActive/WillEnterForeground below? (Not saying it's wrong!)

SmilieKeyboardSetIsAwfulAppActive(false)

updateShortcutItems()
}

func applicationDidBecomeActive(_ application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
SmilieKeyboardSetIsAwfulAppActive(true)

// Screen brightness may have changed while the app wasn't paying attention.
Expand Down Expand Up @@ -155,12 +158,19 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
try! managedObjectContext.save()
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
AppDelegate.instance.application(app, open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation] as Any
)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this necessary?

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
guard
ForumsClient.shared.isLoggedIn,
let route = try? AwfulRoute(url)
else { return false }

else { return false }
open(route: route)
return true
}
Expand All @@ -170,23 +180,29 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
return router.route(route)
}

func fullReset() {
UserDefaults.standard.removeAllObjectsInMainBundleDomain()
emptyCache()
dataStore.deleteStoreAndReset()
logOut()
}

func logOut() {
// Logging out doubles as an "empty cache" button.
let cookieJar = HTTPCookieStorage.shared
for cookie in cookieJar.cookies ?? [] {
cookieJar.deleteCookie(cookie)
}
UserDefaults.standard.removeAllObjectsInMainBundleDomain()
emptyCache()

// Do this after resetting settings so that it gets the default baseURL.

updateClientBaseURL()

if loginViewController == nil {
newLoginController()
}

setRootViewController(loginViewController.enclosingNavigationController, animated: true) { [weak self] in
self?._rootViewControllerStack = nil

self?.urlRouter = nil

self?.dataStore.deleteStoreAndReset()
}
}

Expand Down Expand Up @@ -255,7 +271,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
return stack
}

private lazy var loginViewController: LoginViewController! = {
private func createLoginViewController() -> LoginViewController! {
let loginVC = LoginViewController.newFromStoryboard()
loginVC.completionBlock = { [weak self] (login) in
guard let self = self else { return }
Expand All @@ -266,7 +282,16 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
})
}
return loginVC
}

private lazy var loginViewController : LoginViewController! = {
return self.createLoginViewController()
}()

private func newLoginController() {
loginViewController = createLoginViewController()
}

}

private extension AppDelegate {
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion App/Settings/Settings.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>TitleKey</key>
<string>username</string>
<key>Explanation</key>
<string>Logging out erases all cached forums, threads, and posts.</string>
<string>Full reset erases all cached forums, threads, and posts.</string>
<key>Action</key>
<string>ShowProfile</string>
<key>Settings</key>
Expand All @@ -25,6 +25,12 @@
<key>Action</key>
<string>EmptyCache</string>
</dict>
<dict>
<key>Title</key>
<string>Full Reset</string>
<key>Action</key>
<string>FullReset</string>
</dict>
</array>
</dict>
<dict>
Expand Down
28 changes: 0 additions & 28 deletions App/Templates/Acknowledgements.html.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -146,34 +146,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</pre>
</section>

<section>
<header>
<h1>1Password App Extension</h1>
<a href="https://github.com/AgileBits/onepassword-app-extension">github.com/AgileBits/onepassword-app-extension</a>
</header>

<pre>
Copyright (c) 2014 AgileBits Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</pre>
</section>

<section>
<header>
<h1>PromiseKit</h1>
Expand Down
29 changes: 6 additions & 23 deletions App/View Controllers/Login.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="sm1-AH-1Nj">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="sm1-AH-1Nj">
<device id="retina4_0" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -42,7 +43,7 @@
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Forums Poster" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="hSE-Zs-GjL">
<rect key="frame" x="101" y="35" width="211" height="21"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" smartDashesType="no" smartInsertDeleteType="no" smartQuotesType="no" textContentType="username"/>
<connections>
<action selector="didChangeUsername:" destination="sm1-AH-1Nj" eventType="editingChanged" id="I7Q-Mb-cLz"/>
<outlet property="delegate" destination="sm1-AH-1Nj" id="ruk-IC-WBb"/>
Expand All @@ -63,27 +64,14 @@
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Required" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="w4M-UU-wrF">
<rect key="frame" x="101" y="79.5" width="180" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" secureTextEntry="YES"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" secureTextEntry="YES" smartDashesType="no" smartQuotesType="no" textContentType="password"/>
<connections>
<action selector="didChangePassword:" destination="sm1-AH-1Nj" eventType="editingChanged" id="VYn-PQ-oDY"/>
<outlet property="delegate" destination="sm1-AH-1Nj" id="aKX-yX-zJ3"/>
</connections>
</textField>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="1000" verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="left" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="b7d-gZ-1G0" userLabel="1Password Button">
<rect key="frame" x="285" y="63.5" width="35" height="43"/>
<constraints>
<constraint firstAttribute="height" constant="43" id="BQj-bL-Ppq"/>
<constraint firstAttribute="width" constant="35" id="ITm-Wr-xnM"/>
</constraints>
<state key="normal">
<color key="titleShadowColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
<connections>
<action selector="didTapOnePassword:" destination="sm1-AH-1Nj" eventType="touchUpInside" id="Vwa-P5-7JJ"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="s58-Hg-Zd4" userLabel="Separator 2">
<rect key="frame" x="8" y="106.5" width="304" height="0.5"/>
<rect key="frame" x="8" y="101" width="304" height="0.5"/>
<color key="backgroundColor" red="0.90196079019999997" green="0.90196079019999997" blue="0.90196079019999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="0.5" id="LaD-ad-dfw"/>
Expand All @@ -96,10 +84,7 @@
<constraint firstAttribute="bottom" secondItem="s58-Hg-Zd4" secondAttribute="bottom" id="3qs-uL-Mx9"/>
<constraint firstItem="s58-Hg-Zd4" firstAttribute="top" secondItem="w4M-UU-wrF" secondAttribute="bottom" constant="7" id="5Wu-2K-WDC"/>
<constraint firstItem="hSE-Zs-GjL" firstAttribute="top" secondItem="Q00-dp-PD7" secondAttribute="top" constant="35" id="5d1-rX-pLQ"/>
<constraint firstItem="b7d-gZ-1G0" firstAttribute="top" secondItem="EGY-WJ-vf1" secondAttribute="bottom" id="6WJ-hv-TIb"/>
<constraint firstAttribute="trailing" secondItem="b7d-gZ-1G0" secondAttribute="trailing" id="7cQ-O8-ooj"/>
<constraint firstItem="w4M-UU-wrF" firstAttribute="leading" secondItem="hSE-Zs-GjL" secondAttribute="leading" id="CwA-26-CpY"/>
<constraint firstItem="b7d-gZ-1G0" firstAttribute="leading" secondItem="w4M-UU-wrF" secondAttribute="trailing" constant="4" id="F2V-uR-a0i"/>
<constraint firstItem="mPk-Lj-l4y" firstAttribute="baseline" secondItem="hSE-Zs-GjL" secondAttribute="baseline" id="GMQ-l0-L78"/>
<constraint firstItem="mPk-Lj-l4y" firstAttribute="leading" secondItem="Q00-dp-PD7" secondAttribute="leading" constant="8" id="OY2-kG-uYf"/>
<constraint firstItem="mx3-qK-CFW" firstAttribute="leading" secondItem="Q00-dp-PD7" secondAttribute="leading" constant="8" id="Ty9-3p-XfW"/>
Expand Down Expand Up @@ -207,11 +192,9 @@
<outlet property="consentToTermsTextView" destination="d8m-a5-QTw" id="ZWy-hs-YuA"/>
<outlet property="forgotPasswordButton" destination="c0R-8r-wig" id="kwM-LU-plp"/>
<outlet property="nextBarButtonItem" destination="qPx-kd-mE6" id="2xV-N5-d7X"/>
<outlet property="onePasswordButton" destination="b7d-gZ-1G0" id="e6f-bg-2Cz"/>
<outlet property="passwordTextField" destination="w4M-UU-wrF" id="mPI-pt-5M8"/>
<outlet property="scrollView" destination="BeK-WF-6SC" id="Acb-9a-7Du"/>
<outlet property="usernameTextField" destination="hSE-Zs-GjL" id="QSh-Tf-HjP"/>
<outletCollection property="onePasswordUnavailableConstraints" destination="eCb-Dd-FKt" collectionClass="NSMutableArray" id="maH-Bt-4Ac"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6Cp-xe-tET" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
34 changes: 0 additions & 34 deletions App/View Controllers/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Copyright 2014 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app

import AwfulCore
import MiniOnePassword
import UIKit

private let Log = Logger.get()
Expand All @@ -23,9 +22,6 @@ class LoginViewController: ViewController {
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
@IBOutlet private var consentToTermsTextView: UITextView!

@IBOutlet weak var onePasswordButton: UIButton!
@IBOutlet var onePasswordUnavailableConstraints: [NSLayoutConstraint]!

fileprivate enum State {
case awaitingUsername
case awaitingPassword
Expand Down Expand Up @@ -72,13 +68,6 @@ class LoginViewController: ViewController {

// Can't set this in the storyboard for some reason.
nextBarButtonItem.isEnabled = false

onePasswordButton.setImage(UIImage(named: "onepassword-button"), for: .normal)

if !OnePassword.isAvailable {
onePasswordButton.removeFromSuperview()
view.addConstraints(onePasswordUnavailableConstraints)
}

consentToTermsTextView.attributedText = {
let format = NSAttributedString(string: LocalizedString("login.consent-to-terms.full-text"))
Expand Down Expand Up @@ -129,29 +118,6 @@ class LoginViewController: ViewController {
}
}

@IBAction func didTapOnePassword(_ sender: UIButton) {
view.endEditing(true)

OnePassword.findLogin(
urlString: "forums.somethingawful.com",
presentingViewController: self,
sender: .view(sender),
completion: { result in
switch result {
case let .success(loginInfo):
self.usernameTextField.text = loginInfo.username
self.passwordTextField.text = loginInfo.password
self.state = .canAttemptLogin

case .failure(.userCancelled):
break

case let .failure(error):
Log.e("1Password extension failed: \(error)")
}
})
}

fileprivate func attemptToLogIn() {
assert(state == .canAttemptLogin, "unexpected state")
state = .attemptingLogin
Expand Down
Loading