Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jw.lab3.data;
- import com.jw.lab3.data.model.LoggedInUser;
- import java.io.IOException;
- import java.lang.reflect.Array;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- /**
- * Class that handles authentication w/ login credentials and retrieves user information.
- */
- public class LoginDataSource {
- private List<String> DUMMY_CREDENTIALS = new ArrayList<>();
- public LoginDataSource() {
- DUMMY_CREDENTIALS.add("admin");
- DUMMY_CREDENTIALS.add("admin");
- }
- public Result<LoggedInUser> login(String username, String password) {
- try {
- // TODO: handle loggedInUser authentication
- if (DUMMY_CREDENTIALS.contains(username) && DUMMY_CREDENTIALS.contains(password)) {
- LoggedInUser fakeUser =
- new LoggedInUser(
- java.util.UUID.randomUUID().toString(),
- username);
- return new Result.Success<>(fakeUser);
- } else {
- DUMMY_CREDENTIALS.addAll(Arrays.asList(username, password));
- return new Result.Error(new IOException("Could not log"));
- }
- } catch (Exception e) {
- return new Result.Error(new IOException("Error logging in", e));
- }
- }
- public void logout() {
- // TODO: revoke authentication
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement