Skip to content
Merged
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
91 changes: 63 additions & 28 deletions src/main/java/com/artipie/front/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
import com.artipie.front.settings.YamlRepoPermissions;
import com.artipie.front.ui.HbTemplateEngine;
import com.artipie.front.ui.PostSignIn;
import com.artipie.front.ui.RepoPage;
import com.artipie.front.ui.SignInPage;
import com.artipie.front.ui.UserPage;
import com.artipie.front.ui.repository.RepoAddConfig;
import com.artipie.front.ui.repository.RepoAddInfo;
import com.artipie.front.ui.repository.RepoEdit;
import com.artipie.front.ui.repository.RepoList;
import com.artipie.front.ui.repository.org.RepoListByUser;
import com.artipie.front.ui.repository.RepoRemove;
import com.artipie.front.ui.repository.RepoSave;
import com.artipie.front.ui.repository.RepositoryInfo;
import com.artipie.front.ui.repository.RepositoryTemplate;
import com.fasterxml.jackson.core.JsonParseException;
import com.jcabi.log.Logger;
import java.io.File;
Expand Down Expand Up @@ -283,43 +287,74 @@ void start(final int port) {
"", MimeTypes.Type.APPLICATION_JSON.asString(),
new SignInPage(), engine
);
final AuthService auth = new AuthService(this.settings.artipieEnpoint());
this.ignite.post("", new PostSignIn(auth));
this.ignite.post(
"",
new PostSignIn(
new AuthService(this.settings.artipieEnpoint()),
AuthByPassword.withCredentials(creds)
)
);
}
);
this.ignite.path(
"/dashboard",
() -> {
this.ignite.get(
"",
(req, res) -> {
res.redirect("/dashboard/repository/list");
return "Ok";
}
);
final ArtipieEndpoint endpoint = this.settings.artipieEnpoint();
final RepositoryService repository = new RepositoryService(endpoint);
final RepositoryInfo info = new RepositoryInfo();
final RepositoryTemplate template = new RepositoryTemplate();
this.ignite.path(
"/repository", () -> {
this.ignite.get("/list", new RepoList(repository), engine);
if ("org".equals(this.settings.layout())) {
this.ignite.get("/list/:uname", new RepoListByUser(repository), engine);
final String layout = this.settings.layout();
this.ignite.get("/list", new RepoList(repository, layout), engine);
if ("flat".equals(layout)) {
this.ignite.get(
"/edit/:repo",
new RepoEdit(repository, layout, info),
engine
);
this.ignite.post(
"/update/:repo",
new RepoSave(repository, layout),
engine
);
this.ignite.post(
"/remove/:repo",
new RepoRemove(repository, layout),
engine
);
} else {
this.ignite.get(
"/edit/:user/:repo",
new RepoEdit(repository, layout, info),
engine
);
this.ignite.post(
"/update/:user/:repo",
new RepoSave(repository, layout),
engine
);
this.ignite.post(
"/remove/:user/:repo",
new RepoRemove(repository, layout),
engine
);
}
this.ignite.get("/add/info", new RepoAddInfo(), engine);
this.ignite.get(
"/add/config",
new RepoAddConfig(layout, info, template),
engine
);
}
);
final RepoSettings stn = new RepoSettings(
this.settings.layout(), this.settings.repoConfigsStorage()
);
this.ignite.get("", new UserPage(stn), engine);
this.ignite.get(
new RequestPath().with(Users.USER_PARAM).toString(), new UserPage(stn), engine
);
this.ignite.get(
new RequestPath().with(Users.USER_PARAM)
.with(Repositories.REPO_PARAM).toString(),
new RepoPage.TemplateView(stn), engine
);
this.ignite.post(
new RequestPath().with("api").with("repos").with(Users.USER_PARAM).toString(),
new RepoPage.Post(stn)
);
this.ignite.get(
new RequestPath().with("api").with("repos").with(Users.USER_PARAM).toString(),
new RepoPage.Get()
);
}
);
this.ignite.before(AuthFilters.AUTHENTICATE);
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/com/artipie/front/rest/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package com.artipie.front.rest;

import com.artipie.front.settings.ArtipieEndpoint;
import java.net.http.HttpResponse;
import io.vavr.Tuple3;
import java.util.Optional;
import javax.json.Json;
import javax.servlet.http.HttpServletResponse;

/**
* Auth-service.
Expand All @@ -29,22 +29,23 @@ public AuthService(final ArtipieEndpoint endpoint) {
}

/**
* Obtains JWT-token from auth rest-service.
*
* Obtain JWT-token from auth rest-service.
* @param name User name.
* @param password User password.
* @return JWT-token.
* @return Tuple3 of 'Status code, JWT-token, Error message'.
*/
public String getJwtToken(final String name, final String password) {
final HttpResponse<String> response = this.httpPost(
AuthService.TOKEN_PATH,
() ->
Json.createObjectBuilder()
.add("name", name)
.add("pass", password)
.build().toString()
public Tuple3<Integer, String, String> getJwtToken(final String name, final String password) {
return BaseService.handle(
this.httpPost(
Optional.empty(),
AuthService.TOKEN_PATH,
() ->
Json.createObjectBuilder()
.add("name", name)
.add("pass", password)
.build().toString()
),
res -> BaseService.jsonObject(res).getString("token")
);
checkStatus(HttpServletResponse.SC_OK, response);
return BaseService.jsonObject(response).getString("token");
}
}
Loading