Skip to content

Commit

Permalink
Added logout button
Browse files Browse the repository at this point in the history
  • Loading branch information
zaru committed Feb 12, 2017
1 parent d35e132 commit 6326dba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NotifyHub/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele

func fetchAccessToken(code: String) {
let keys = NotifyhubKeys()
print("fetchAccessToken")
print(code)

let url: NSURL = NSURL(string: "https://github.com/login/oauth/access_token")!
let body: NSMutableDictionary = NSMutableDictionary()
Expand Down
7 changes: 6 additions & 1 deletion NotifyHub/GitHubModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ class GitHubModel {
let ud = NSUserDefaults.standardUserDefaults()
ud.setObject(accessToken, forKey: "access_token")
}
}

func removeAccessAotken() {
let ud = NSUserDefaults.standardUserDefaults()
ud.removeObjectForKey("access_token")
}
}
13 changes: 13 additions & 0 deletions NotifyHub/NotifyHubViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
//

import Cocoa
//import Keys
import Alamofire
import AlamofireImage
import SwiftyJSON

class NotifyHubViewController: NSViewController, NSSearchFieldDelegate {

@IBOutlet weak var logoutBtn: NSButton!
@IBOutlet weak var preferenceBtn: NSButton!
@IBOutlet weak var searchField: NSSearchField!
@IBOutlet weak var tableView: NSTableView!
Expand All @@ -38,6 +40,8 @@ class NotifyHubViewController: NSViewController, NSSearchFieldDelegate {
}

self.preferenceBtn.action = #selector(openPreference)
self.logoutBtn.action = #selector(logOut)

}

override func controlTextDidChange(obj: NSNotification) {
Expand All @@ -51,6 +55,15 @@ class NotifyHubViewController: NSViewController, NSSearchFieldDelegate {
self.tableView.reloadData()
}

func logOut (){
let body: NSMutableDictionary = NSMutableDictionary()
body.removeObjectForKey("code")

let gitHubModel = GitHubModel()
gitHubModel.removeAccessAotken()

}

func openPreference (){
let preferenceViewController = PreferenceViewController()
self.presentViewControllerAsModalWindow(preferenceViewController)
Expand Down
14 changes: 12 additions & 2 deletions NotifyHub/NotifyHubViewController.xib
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NotifyHubViewController" customModule="NotifyHub" customModuleProvider="target">
<connections>
<outlet property="logoutBtn" destination="8h5-wh-5vg" id="4gb-mI-0HT"/>
<outlet property="preferenceBtn" destination="xa3-Ys-LO5" id="wRi-Js-gK0"/>
<outlet property="searchField" destination="TbN-s4-tsN" id="pSe-f5-lAf"/>
<outlet property="tableView" destination="vgc-lh-bWy" id="eoa-xL-56R"/>
Expand Down Expand Up @@ -81,6 +83,14 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8h5-wh-5vg">
<rect key="frame" x="194" y="2" width="80" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="log out" bezelStyle="roundedRect" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Wec-Kg-sQI">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
</button>
</subviews>
</customView>
</objects>
Expand Down

0 comments on commit 6326dba

Please sign in to comment.