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

Signup updates #15

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bf293fa
started login
Oct 10, 2023
2a5ae64
post method to make new user works, messy otherwise
jenny4567 Oct 10, 2023
7ad2c17
Make login button functional
nayan0499 Oct 10, 2023
47b9b55
Allow user to inherit encodable
nayan0499 Oct 10, 2023
ae8bc9c
Implement login function
nayan0499 Oct 10, 2023
b6af73a
Updated login so that navigation works
Oct 10, 2023
6cc0fae
sign-up page adds user and redirects to welcome page. Hardcoded login…
jenny4567 Oct 10, 2023
c76d654
Modify btn function
nayan0499 Oct 11, 2023
620b1dc
Modify login function
nayan0499 Oct 11, 2023
6f1e862
Fixed autocapitalization, finished login functionality
Oct 11, 2023
cc07297
Merge pull request #1 from jenny4567/login
jenny4567 Oct 11, 2023
8135278
Add a token var
nayan0499 Oct 11, 2023
cb0f2d8
Merge pull request #2 from jenny4567/login
jenny4567 Oct 11, 2023
b02a274
Posts view page and post model
jenny4567 Oct 11, 2023
1b216ff
Merge posts_page branch
nayan0499 Oct 11, 2023
483e52f
Merge pull request #3 from jenny4567/login
jenny4567 Oct 11, 2023
c7c7e45
chaos, many erros
jenny4567 Oct 11, 2023
8513fd0
new posts and view posts, trying to make posts accessible in view as …
jenny4567 Oct 12, 2023
766f58b
Posts page allows creation of new posts and displays posts when butto…
jenny4567 Oct 12, 2023
ea0e5e8
Merge branch 'main' into posts_as_string
jenny4567 Oct 12, 2023
9a66b3d
Merge pull request #4 from jenny4567/posts_as_string
Michaela-VF Oct 12, 2023
619c41e
Revert "Posts as string"
banji-hx Oct 12, 2023
7d37846
Merge pull request #5 from jenny4567/revert-4-posts_as_string
jenny4567 Oct 12, 2023
eba7be4
feed add and trying commit with pxbjoxe file
banji-hx Oct 12, 2023
70760aa
Merge branch 'main' of https://github.com/jenny4567/swiftui-engineeri…
banji-hx Oct 12, 2023
4692a27
added design to welcome view
banji-hx Oct 13, 2023
93b3667
Added last changes and Logout branch changes
Michaela-VF Oct 13, 2023
8ec4704
signup page and errors messages
jenny4567 Oct 13, 2023
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
22 changes: 21 additions & 1 deletion MobileAcebook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
10D70DA82AD44C30003B552B /* LogInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10D70DA72AD44C30003B552B /* LogInView.swift */; };
644CCB672AD83752003CAA85 /* Token.swift in Sources */ = {isa = PBXBuildFile; fileRef = 644CCB662AD83752003CAA85 /* Token.swift */; };
644CCB692AD837E5003CAA85 /* PostsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 644CCB682AD837E5003CAA85 /* PostsView.swift */; };
644CCB6C2AD83868003CAA85 /* SignUpPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 644CCB6A2AD83864003CAA85 /* SignUpPage.swift */; };
9105C5752AD6C3BB00ABFC89 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9105C5742AD6C3BB00ABFC89 /* Post.swift */; };
AE5D85B02AC8A221009680C6 /* MobileAcebookApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5D85AF2AC8A221009680C6 /* MobileAcebookApp.swift */; };
AE5D85B42AC8A224009680C6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AE5D85B32AC8A224009680C6 /* Assets.xcassets */; };
AE5D85B72AC8A224009680C6 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AE5D85B62AC8A224009680C6 /* Preview Assets.xcassets */; };
Expand Down Expand Up @@ -39,6 +44,11 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
10D70DA72AD44C30003B552B /* LogInView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInView.swift; sourceTree = "<group>"; };
644CCB662AD83752003CAA85 /* Token.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Token.swift; sourceTree = "<group>"; };
644CCB682AD837E5003CAA85 /* PostsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PostsView.swift; path = "Preview Content/PostsView.swift"; sourceTree = "<group>"; };
644CCB6A2AD83864003CAA85 /* SignUpPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpPage.swift; sourceTree = "<group>"; };
9105C5742AD6C3BB00ABFC89 /* Post.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = "<group>"; };
AE5D85AC2AC8A221009680C6 /* MobileAcebook.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MobileAcebook.app; sourceTree = BUILT_PRODUCTS_DIR; };
AE5D85AF2AC8A221009680C6 /* MobileAcebookApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileAcebookApp.swift; sourceTree = "<group>"; };
AE5D85B32AC8A224009680C6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -104,13 +114,16 @@
AE5D85AE2AC8A221009680C6 /* MobileAcebook */ = {
isa = PBXGroup;
children = (
644CCB6A2AD83864003CAA85 /* SignUpPage.swift */,
AE5D85D92AC8A337009680C6 /* WelcomePageView.swift */,
644CCB682AD837E5003CAA85 /* PostsView.swift */,
10D70DA72AD44C30003B552B /* LogInView.swift */,
AE5D85E42AC9B060009680C6 /* Protocols */,
AE5D85DF2AC9AF83009680C6 /* Models */,
AE5D85DD2AC9AF72009680C6 /* Services */,
AE5D85AF2AC8A221009680C6 /* MobileAcebookApp.swift */,
AE5D85B32AC8A224009680C6 /* Assets.xcassets */,
AE5D85B52AC8A224009680C6 /* Preview Content */,
AE5D85D92AC8A337009680C6 /* WelcomePageView.swift */,
);
path = MobileAcebook;
sourceTree = "<group>";
Expand Down Expand Up @@ -161,7 +174,9 @@
AE5D85DF2AC9AF83009680C6 /* Models */ = {
isa = PBXGroup;
children = (
9105C5742AD6C3BB00ABFC89 /* Post.swift */,
AE5D85E72AC9B29A009680C6 /* User.swift */,
644CCB662AD83752003CAA85 /* Token.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -304,10 +319,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
644CCB672AD83752003CAA85 /* Token.swift in Sources */,
644CCB6C2AD83868003CAA85 /* SignUpPage.swift in Sources */,
10D70DA82AD44C30003B552B /* LogInView.swift in Sources */,
AE5D85E12AC9AFA9009680C6 /* AuthenticationService.swift in Sources */,
AE5D85E62AC9B077009680C6 /* AuthenticationServiceProtocol.swift in Sources */,
AE5D85B02AC8A221009680C6 /* MobileAcebookApp.swift in Sources */,
AE5D85E82AC9B29A009680C6 /* User.swift in Sources */,
9105C5752AD6C3BB00ABFC89 /* Post.swift in Sources */,
644CCB692AD837E5003CAA85 /* PostsView.swift in Sources */,
AE5D85DA2AC8A337009680C6 /* WelcomePageView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file added MobileAcebook/.DS_Store
Binary file not shown.
Binary file added MobileAcebook/Assets.xcassets/.DS_Store
Binary file not shown.
78 changes: 78 additions & 0 deletions MobileAcebook/LogInView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// LogInView.swift
// MobileAcebook
//
// Created by Ami Day on 09/10/2023.
//
import Foundation
import SwiftUI
import Combine

struct LogInView: View {
@EnvironmentObject var token: Token
@State private var userModel = User(email: "", password: "")
@State private var loggedIn = false
private func onEmailInputChanged(changedEmail: String) {
userModel.email = changedEmail
}
private func onPasswordInputChanged(changedPassword: String) {
userModel.password = changedPassword
}
let authenticationService = AuthenticationService()
var body: some View {
NavigationView {
ZStack {
VStack {

Image("makers-logo")
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.accessibilityIdentifier("makers-logo")

LabeledContent {
TextField("Email", text: $userModel.email).textInputAutocapitalization(.never)
} label: {
Text("Email")
}.onChange(of: userModel.email, perform: onEmailInputChanged)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

LabeledContent {
SecureField("Password", text: $userModel.password).textInputAutocapitalization(.never)
} label: {
Text("Password")
}.onChange(of: userModel.password, perform: onPasswordInputChanged)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button(action: {
authenticationService.login(user: userModel) { isSuccess in
if isSuccess {
loggedIn = true
}
// print("4")
self.token.content = authenticationService.userToken
}
// print("2")
}) {
Text("Login")
}
.accessibilityIdentifier("LoginButton")
NavigationLink(destination: PostsView().navigationBarBackButtonHidden(true), isActive: $loggedIn) { EmptyView() }

Text("\(authenticationService.error_message)").foregroundColor(.red)

NavigationLink("Sign Up", destination: SignUpView().navigationBarBackButtonHidden(true))
.accessibilityIdentifier("signUpButton")
}
Spacer()
}
}
}
}
struct LogInView_Previews: PreviewProvider {
static var previews: some View {
LogInView().environmentObject(Token())
}
}
10 changes: 10 additions & 0 deletions MobileAcebook/Models/Post.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Post.swift
// MobileAcebook
//
// Created by Jenny Wark on 11/10/2023.
//

public struct Post {
let message: String
}
6 changes: 6 additions & 0 deletions MobileAcebook/Models/Token.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
import SwiftUI

class Token: ObservableObject {
@Published var content = "no token set"
}
6 changes: 3 additions & 3 deletions MobileAcebook/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Josué Estévez Fernández on 01/10/2023.
//

public struct User {
let username: String
let password: String
public struct User: Encodable {
var email: String
var password: String
}
77 changes: 77 additions & 0 deletions MobileAcebook/Preview Content/PostsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// PostsView.swift
// MobileAcebook
//
// Created by Jenny Wark on 11/10/2023.
//
import SwiftUI

struct PostsView: View {
@EnvironmentObject var token: Token
@State private var authenticationService = AuthenticationService()
@State private var post_content: String = ""
@State private var posts_array: Array<String> = []
@State private var loggedIn = false
var body: some View {
NavigationView {
VStack {
Spacer()

Text("Posts")
.font(.largeTitle)
.padding(.bottom, 20)
.accessibilityIdentifier("welcomeText")
Spacer()

Image("makers-logo")
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.accessibilityIdentifier("makers-logo")
Spacer()

TextField("Write a post", text: $post_content)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()

Button(action: {
authenticationService.createPost(post: Post(message: post_content), token: token)
}) {
Text("Create Post")
}
.accessibilityIdentifier("CreatePostButton")
Spacer()

Button(action: {
authenticationService.allPosts(token: token) { isSuccess in
if isSuccess {
loggedIn = true
}
// print("4")
self.token.content = authenticationService.userToken
posts_array = authenticationService.posts_array
}
// print("2")
}) {
Text("Show posts")
}
.accessibilityIdentifier("PostsButton")
Text("\(posts_array.joined(separator: " "))")
Spacer()

NavigationLink(destination: WelcomePageView()) {
Text("Logout")
.padding()
.background(Color.blue)
.foregroundColor(Color.white)
.cornerRadius(10)
}
}
}
}
}
struct PostsView_Previews: PreviewProvider {
static var previews: some View {
PostsView().environmentObject(Token())
}
}
Loading