You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
4 years ago
|
//
|
||
|
// LoginView.swift
|
||
|
// Weibo
|
||
|
//
|
||
|
// Created by Qihua Pan on 2020/8/17.
|
||
|
// Copyright © 2020 Qihua Pan. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import SwiftUI
|
||
|
import CoreData
|
||
|
|
||
|
|
||
|
|
||
|
struct LoginView: View {
|
||
|
|
||
|
@Environment(\.managedObjectContext) var contenxt:NSManagedObjectContext
|
||
|
|
||
|
@EnvironmentObject var user:User
|
||
|
|
||
|
func login() {
|
||
|
let request=WBAuthorizeRequest()
|
||
|
request.redirectURI="https://api.weibo.com/oauth2/default.html"
|
||
|
WeiboSDK.send(request)
|
||
|
}
|
||
|
|
||
|
var body: some View {
|
||
|
VStack {
|
||
|
if (self.$user.uid.wrappedValue != nil){
|
||
|
Text("uid=\(self.$user.uid.wrappedValue!)")
|
||
|
}else{
|
||
|
Button(action: {
|
||
|
self.login()
|
||
|
}) {
|
||
|
Text("跳转到授权登陆页面")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
struct LoginView_Previews: PreviewProvider {
|
||
|
|
||
|
static var previews: some View {
|
||
|
LoginView().environment(\.managedObjectContext, UserData.getContext()).environmentObject(UserData.getUser())
|
||
|
}
|
||
|
}
|