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

biometric authentication #350

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions AmahiAnywhere/AmahiAnywhere.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
46657183205085FC000E0D45 /* FilesPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46657182205085FC000E0D45 /* FilesPresenter.swift */; };
46CB896B204FB0FC0031151F /* SharesPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46CB896A204FB0FC0031151F /* SharesPresenter.swift */; };
46F87397204CC69500F1AF37 /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F87396204CC69500F1AF37 /* Server.swift */; };
7215CACF24E55B230001CEF4 /* SettingsBiometricTVCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7215CACE24E55B230001CEF4 /* SettingsBiometricTVCell.swift */; };
7241C6E124E5B7A700415406 /* SettingsBiometricTVCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7241C6E024E5B7A700415406 /* SettingsBiometricTVCell.xib */; };
7253F21824BDA89F0094C385 /* AudioThumbnailCollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7253F21624BDA89F0094C385 /* AudioThumbnailCollectionCell.swift */; };
7253F21924BDA89F0094C385 /* AudioThumbnailCollectionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7253F21724BDA89F0094C385 /* AudioThumbnailCollectionCell.xib */; };
7253F21B24BDAF890094C385 /* AudioPlayerViewController+CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7253F21A24BDAF890094C385 /* AudioPlayerViewController+CollectionView.swift */; };
Expand Down Expand Up @@ -215,6 +217,8 @@
46F87396204CC69500F1AF37 /* Server.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Server.swift; sourceTree = "<group>"; };
499AAFCDBDAB4C05C7264992 /* Pods-AmahiAnywhere.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AmahiAnywhere.release.xcconfig"; path = "Pods/Target Support Files/Pods-AmahiAnywhere/Pods-AmahiAnywhere.release.xcconfig"; sourceTree = "<group>"; };
665E1C7EF1F0DEBF3A9809B0 /* Pods-AmahiAnywhere.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AmahiAnywhere.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AmahiAnywhere/Pods-AmahiAnywhere.debug.xcconfig"; sourceTree = "<group>"; };
7215CACE24E55B230001CEF4 /* SettingsBiometricTVCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsBiometricTVCell.swift; sourceTree = "<group>"; };
7241C6E024E5B7A700415406 /* SettingsBiometricTVCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsBiometricTVCell.xib; sourceTree = "<group>"; };
7253F21624BDA89F0094C385 /* AudioThumbnailCollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioThumbnailCollectionCell.swift; sourceTree = "<group>"; };
7253F21724BDA89F0094C385 /* AudioThumbnailCollectionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AudioThumbnailCollectionCell.xib; sourceTree = "<group>"; };
7253F21A24BDAF890094C385 /* AudioPlayerViewController+CollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AudioPlayerViewController+CollectionView.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -650,6 +654,7 @@
C8DA5B2120D5E0C600F5A527 /* Cells */ = {
isa = PBXGroup;
children = (
7215CACE24E55B230001CEF4 /* SettingsBiometricTVCell.swift */,
3BCAFBA022C537C10044057E /* DownloadsListCollectionCell.swift */,
3BCAFBA222C537DE0044057E /* DownloadsGridCollectionCell.swift */,
3BCAFBA422C5385D0044057E /* DownloadsBaseCollectionCell.swift */,
Expand All @@ -666,6 +671,7 @@
72BDA8B424A9ED6900B4469E /* QueueItemTableViewCell.xib */,
7253F21624BDA89F0094C385 /* AudioThumbnailCollectionCell.swift */,
7253F21724BDA89F0094C385 /* AudioThumbnailCollectionCell.xib */,
7241C6E024E5B7A700415406 /* SettingsBiometricTVCell.xib */,
);
path = Cells;
sourceTree = "<group>";
Expand Down Expand Up @@ -792,6 +798,7 @@
FB71BEA2201CB2FC0005492C /* LaunchScreen.storyboard in Resources */,
FB71BE9F201CB2FC0005492C /* Assets.xcassets in Resources */,
72BDA8B624A9ED6900B4469E /* QueueItemTableViewCell.xib in Resources */,
7241C6E124E5B7A700415406 /* SettingsBiometricTVCell.xib in Resources */,
3B24FE1822970B6B0044721D /* WalkthroughCell.xib in Resources */,
3B24FE162297086A0044721D /* WalkthroughAmahiCell.xib in Resources */,
FB71BE9D201CB2FC0005492C /* Main.storyboard in Resources */,
Expand Down Expand Up @@ -943,6 +950,7 @@
C8DA5B1820D5D7EA00F5A527 /* Download.swift in Sources */,
3B2805E62312DE930022ED48 /* RecentFilesViewController+CollectionView.swift in Sources */,
8A67FC2B22666F81005A5038 /* OfflineFile+MimeType.swift in Sources */,
7215CACF24E55B230001CEF4 /* SettingsBiometricTVCell.swift in Sources */,
80F3FDC7206C0D4D0061CD51 /* ConnectionViewController.swift in Sources */,
3B1B35A423080E710058B1D8 /* UINavigationItem.swift in Sources */,
3B2805EC2312DFFF0022ED48 /* RecentFilesViewController+Remote.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions AmahiAnywhere/AmahiAnywhere/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let mainStoryboard: UIStoryboard = UIStoryboard(name: StoryBoardIdentifiers.main, bundle: nil)
var initialViewController: UIViewController? = nil

LocalStorage.shared.persist(bool: false, for: PersistenceIdentifiers.overrideBiometric)

if LocalStorage.shared.contains(key: PersistenceIdentifiers.accessToken) {

if useCastContainerViewController {
Expand Down
30 changes: 30 additions & 0 deletions AmahiAnywhere/AmahiAnywhere/Cells/SettingsBiometricTVCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SettingsBiometricTVCellTableViewCell.swift
// AmahiAnywhere
//
// Created by Shresth Pratap Singh on 13/08/20.
// Copyright © 2020 Amahi. All rights reserved.
//

import UIKit

class SettingsBiometricTVCell: UITableViewCell {

@IBOutlet weak var toggleSwitch: UISwitch!
@IBOutlet weak var titleLabel:UILabel!
weak var delegate: SettingsViewController?

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

@IBAction func toggleAction(_ sender: Any) {
if toggleSwitch.isOn{
delegate?.turnOnBiometric()
}else{
delegate?.turnOffBiometric()
}
}

}
54 changes: 54 additions & 0 deletions AmahiAnywhere/AmahiAnywhere/Cells/SettingsBiometricTVCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="SettingsBiometricTVCell" rowHeight="58" id="7T1-to-j5g" customClass="SettingsBiometricTVCell" customModule="AmahiAnywhere" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="434" height="58"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="7T1-to-j5g" id="Jhl-Ls-XCV">
<rect key="frame" x="0.0" y="0.0" width="434" height="58"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="bTE-QY-nh5">
<rect key="frame" x="379" y="14" width="37" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="35" id="lc0-hr-UbR"/>
<constraint firstAttribute="height" constant="30" id="n2U-sJ-1c7"/>
</constraints>
<connections>
<action selector="toggleAction:" destination="7T1-to-j5g" eventType="valueChanged" id="rjw-53-0zP"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Use face/touch ID to login" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IT0-CW-oKa">
<rect key="frame" x="17" y="0.0" width="347" height="58"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="IT0-CW-oKa" firstAttribute="leading" secondItem="Jhl-Ls-XCV" secondAttribute="leading" constant="17" id="3Kh-6U-Lsz"/>
<constraint firstItem="bTE-QY-nh5" firstAttribute="centerY" secondItem="IT0-CW-oKa" secondAttribute="centerY" id="AEV-c0-ilV"/>
<constraint firstAttribute="trailing" secondItem="bTE-QY-nh5" secondAttribute="trailing" constant="20" id="ZnG-Ye-2IS"/>
<constraint firstItem="IT0-CW-oKa" firstAttribute="top" secondItem="Jhl-Ls-XCV" secondAttribute="top" id="flI-gg-N0Z"/>
<constraint firstAttribute="bottom" secondItem="IT0-CW-oKa" secondAttribute="bottom" id="rFn-kc-QjB"/>
<constraint firstItem="bTE-QY-nh5" firstAttribute="leading" secondItem="IT0-CW-oKa" secondAttribute="trailing" constant="15" id="y6M-d8-wVc"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="titleLabel" destination="IT0-CW-oKa" id="b2b-Ht-rEm"/>
<outlet property="toggleSwitch" destination="bTE-QY-nh5" id="11Y-ul-qqy"/>
</connections>
<point key="canvasLocation" x="133.33333333333334" y="144.64285714285714"/>
</tableViewCell>
</objects>
</document>
17 changes: 17 additions & 0 deletions AmahiAnywhere/AmahiAnywhere/Data/Local/LocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ final class LocalStorage: NSObject {
UserDefaults.standard.setValue(string, forKey: key);
UserDefaults.standard.synchronize();
}

public func persist(bool: Bool, for key:String){
UserDefaults.standard.set(bool, forKey: key)
}

public func getString(key: String!) -> String? {
UserDefaults.standard.synchronize()
return UserDefaults.standard.value(forKey: key) as? String;
}

public func getBool(for key: String) -> Bool{
return UserDefaults.standard.bool(forKey: key)
}

public func contains(key: String!) -> Bool{
return UserDefaults.standard.object(forKey: key) != nil
}
Expand All @@ -37,8 +45,17 @@ final class LocalStorage: NSObject {
}

public func logout(_ complete: () -> Void){
var permissionAsked = false
var biometricEnabled = false
//saving permision state for biometrics
if contains(key: PersistenceIdentifiers.biometricLoginPermissionAsked){
permissionAsked = getBool(for: PersistenceIdentifiers.biometricLoginPermissionAsked)
biometricEnabled = getBool(for: PersistenceIdentifiers.biometricEnabled)
}
clearAll()
persistString(string: "completed", key: "walkthrough")
persist(bool: permissionAsked, for: PersistenceIdentifiers.biometricLoginPermissionAsked)
persist(bool: biometricEnabled , for: PersistenceIdentifiers.biometricEnabled)
complete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ struct PersistenceIdentifiers {

static let accessToken = "access_token"
static let prefConnection = "pref_connection"
static let biometricLoginPermissionAsked = "biometric_login"
static let biometricEnabled = "biometric_enabled"
static let overrideBiometric = "biometric_override"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct StringLiterals {
static let emailErrorTitle = "Couldn't Send Mail"
static let emailErrorMessage = "Your Device Couldn't Send Mail"
static let disabled = "Disabled"
static let accountSectionSubItems = ["Sign Out"]
static let accountSectionSubItems = ["Sign Out","Login with face/touch ID"]
static let settingsSectionSubItems = ["Connection", clearCacheTitle]
static let aboutSectionSubItems = ["Version", "Tell a friend"]
static let settingsSectionsTitle = ["Account", "Settings", "About"]
Expand Down
2 changes: 2 additions & 0 deletions AmahiAnywhere/AmahiAnywhere/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSFaceIDUsageDescription</key>
<string>Use FaceID to log in</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand Down
Loading