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

Templete/feature/sign in #72

Draft
wants to merge 5 commits into
base: develop
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "image 2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 62 additions & 47 deletions portfolio-ios-swiftui/portfolio-ios-swiftui/Login/LoginPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,74 @@ import SwiftUI

struct LoginPage: View {
@ObservedObject var login = LoginViewModel()
@State private var isLinkActive = false
@State private var isSignupLinkActive = false

var body: some View {
VStack {
VStack(alignment: .leading) {
Text("メールアドレス")
.foregroundColor(Color.text)
TextField("入力してください", text: $login.mail)
.frame(width: 240, height: 40)
.padding(.leading, 15)
.overlay(RoundedRectangle(cornerRadius: 20)
if #available(iOS 16.0, *) {
NavigationStack {
VStack {
VStack(alignment: .leading) {
Text("メールアドレス")
.foregroundColor(Color.text)
TextField("入力してください", text: $login.mail)
.frame(width: 240, height: 40)
.padding(.leading, 15)
.overlay(RoundedRectangle(cornerRadius: 20)
.stroke(Color.grayBottonColor, lineWidth: 2)
)
.padding(.leading, 25)
}
.padding(.trailing, 30)
.padding(.bottom)

VStack(alignment: .leading) {
Text("パスワード")
.foregroundColor(Color.text)
TextField("入力してください", text: $login.password)
.frame(width: 240, height: 40)
.padding(.leading, 15)
.overlay(RoundedRectangle(cornerRadius: 20)
)
.padding(.leading, 25)
}
.padding(.trailing, 30)
.padding(.bottom)
VStack(alignment: .leading) {
Text("パスワード")
.foregroundColor(Color.text)
TextField("入力してください", text: $login.password)
.frame(width: 240, height: 40)
.padding(.leading, 15)
.overlay(RoundedRectangle(cornerRadius: 20)
.stroke(Color.grayBottonColor, lineWidth: 2)
)
.padding(.leading, 25)
}
.padding(.trailing, 30)
.padding(.bottom)

BaseButtonView(
action: {
login.fetchLoginService()
},
labelText: "ログイン  ",
foregroundColor: Color.white,
backgroundColor: Color.subPink,
radius: 25
)
.padding(.top)

Divider()
.padding(.top, 30)

// 新規会員登録ボタン
NavigationLink(destination: SignupPage(), isActive: $isSignupLinkActive) {
EmptyView()
}

BaseButtonView(
action: {
isSignupLinkActive = true
},
labelText: "新規会員登録",
foregroundColor: Color.text,
backgroundColor: Color.grayBottonColor,
radius: 25
)
.padding(.leading, 25)
.padding(.top, 60)
}
}
.padding(.trailing, 30)
.padding(.bottom)

BaseButtonView(
action: {
login.fetchLoginService()
},
labelText: "ログイン  ",
foregroundColor: Color.white,
backgroundColor: Color.subPink,
radius: 25
)
.padding(.top)

Divider()
.padding(.top, 30)

BaseButtonView(
action: {},
labelText: "新規会員登録",
foregroundColor: Color.text,
backgroundColor: Color.grayBottonColor,
radius: 25
)
.padding(.top, 60)
} else {
// Fallback on earlier versions
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// SignupService.swift
// portfolio-ios-swiftui
//
// Created by 鳥山英峻 on 2023/02/27.
//

import Foundation

final class SignupAPIService {

static let shared = SignupAPIService()
private init() {}

public func fetchSignupService(displayName: String, userIcon: String, familyName: String, firstName: String, mail: String, password: String, grade: String, course: String) async throws -> Register {

let body: [String: String] = [
"icon": "\(userIcon)",
"familyName": "\(familyName)",
"firstName": "\(firstName)",
"mail": "\(mail)",
"password": "\(password)",
"grade": "\(grade)",
"course": "\(course)",
"displayName": "\(displayName)"
]

// MARK: - 1.API取得先URLの作成
// 本番環境ではURLを変更する
let baseURL: URL = .init(string: "http://localhost:9000/sign/up")!
var request = URLRequest(url: baseURL)

// MARK: - 2.URLリクエストの作成
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed)

// MARK: - 3.TASKの作成
let data = try await URLSession.shared.data(for: request)
let response = try JSONDecoder().decode(Register.self, from: data.0)

return response
}
}
Loading