Search in sources :

Example 1 with CfUser

use of io.clownfish.clownfish.dbentities.CfUser in project Clownfish by rawdog71.

the class CfUserDAOImpl method findById.

@Override
public CfUser findById(Long id) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfUser.findById");
    query.setParameter("id", id);
    CfUser cfuser = (CfUser) query.getSingleResult();
    return cfuser;
}
Also used : CfUser(io.clownfish.clownfish.dbentities.CfUser) TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session)

Example 2 with CfUser

use of io.clownfish.clownfish.dbentities.CfUser in project Clownfish by rawdog71.

the class CfUserDAOImpl method findAll.

@Override
public List<CfUser> findAll() {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfUser.findAll");
    List<CfUser> cfuserlist = query.getResultList();
    return cfuserlist;
}
Also used : CfUser(io.clownfish.clownfish.dbentities.CfUser) TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session)

Example 3 with CfUser

use of io.clownfish.clownfish.dbentities.CfUser in project Clownfish by rawdog71.

the class BackendLoginServlet method processRequest.

protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
    Map<String, String[]> parameters = request.getParameterMap();
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("email") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        email = values[0];
    });
    String inst_email = email;
    parameters.keySet().stream().filter((paramname) -> (paramname.compareToIgnoreCase("password") == 0)).map((paramname) -> parameters.get(paramname)).forEach((values) -> {
        password = values[0];
    });
    String inst_password = password;
    AuthToken at = null;
    if ((null != inst_email) && (null != inst_password)) {
        try {
            CfUser cfuser = cfuserService.findByEmail(inst_email);
            String salt = cfuser.getSalt();
            String secure = PasswordUtil.generateSecurePassword(inst_password, salt);
            if (secure.compareTo(cfuser.getPasswort()) == 0) {
                String token = AuthToken.generateToken(inst_password, salt);
                // Tokens valid for 60 minutes
                at = new AuthToken(token, new DateTime().plusMinutes(60), cfuser);
                authtokenlist.getAuthtokens().put(token, at);
            } else {
                // Invalid token
                at = new AuthToken("", new DateTime(), null);
            }
        } catch (Exception ex) {
            // Invalid token
            at = new AuthToken("", new DateTime(), null);
        }
    }
    Gson gson = new Gson();
    String json = gson.toJson(at);
    response.setContentType("application/json;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.print(json);
    } catch (IOException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : PrintWriter(java.io.PrintWriter) Logger(org.slf4j.Logger) HttpServlet(javax.servlet.http.HttpServlet) ServletException(javax.servlet.ServletException) HttpServletResponse(javax.servlet.http.HttpServletResponse) DateTime(org.joda.time.DateTime) LoggerFactory(org.slf4j.LoggerFactory) AuthToken(io.clownfish.clownfish.datamodels.AuthToken) AuthTokenList(io.clownfish.clownfish.datamodels.AuthTokenList) PasswordUtil(io.clownfish.clownfish.utils.PasswordUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) CfUser(io.clownfish.clownfish.dbentities.CfUser) WebServlet(javax.servlet.annotation.WebServlet) HttpServletRequest(javax.servlet.http.HttpServletRequest) Component(org.springframework.stereotype.Component) Gson(com.google.gson.Gson) Map(java.util.Map) CfUserService(io.clownfish.clownfish.serviceinterface.CfUserService) CfUser(io.clownfish.clownfish.dbentities.CfUser) AuthToken(io.clownfish.clownfish.datamodels.AuthToken) Gson(com.google.gson.Gson) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 4 with CfUser

use of io.clownfish.clownfish.dbentities.CfUser in project Clownfish by rawdog71.

the class UserList method onCreateUser.

public void onCreateUser(ActionEvent actionEvent) {
    try {
        CfUser newuser = new CfUser();
        newuser.setEmail(email);
        newuser.setVorname(vorname);
        newuser.setNachname(nachname);
        newuser.setAssetref(avatar);
        newuser.setPasswort(passwort);
        String salt = PasswordUtil.getSalt(30);
        String secure = PasswordUtil.generateSecurePassword(passwort, salt);
        newuser.setSalt(salt);
        newuser.setPasswort(secure);
        cfuserService.create(newuser);
        userlist = cfuserService.findAll();
    } catch (ConstraintViolationException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : CfUser(io.clownfish.clownfish.dbentities.CfUser) ConstraintViolationException(jakarta.validation.ConstraintViolationException)

Example 5 with CfUser

use of io.clownfish.clownfish.dbentities.CfUser in project Clownfish by rawdog71.

the class CfUserDAOImpl method findByEmail.

@Override
public CfUser findByEmail(String email) {
    Session session = this.sessionFactory.getCurrentSession();
    TypedQuery query = (TypedQuery) session.getNamedQuery("CfUser.findByEmail");
    query.setParameter("email", email);
    CfUser cfuser = (CfUser) query.getSingleResult();
    return cfuser;
}
Also used : CfUser(io.clownfish.clownfish.dbentities.CfUser) TypedQuery(javax.persistence.TypedQuery) Session(org.hibernate.Session)

Aggregations

CfUser (io.clownfish.clownfish.dbentities.CfUser)5 TypedQuery (javax.persistence.TypedQuery)3 Session (org.hibernate.Session)3 Gson (com.google.gson.Gson)1 AuthToken (io.clownfish.clownfish.datamodels.AuthToken)1 AuthTokenList (io.clownfish.clownfish.datamodels.AuthTokenList)1 CfUserService (io.clownfish.clownfish.serviceinterface.CfUserService)1 PasswordUtil (io.clownfish.clownfish.utils.PasswordUtil)1 ConstraintViolationException (jakarta.validation.ConstraintViolationException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 WebServlet (javax.servlet.annotation.WebServlet)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DateTime (org.joda.time.DateTime)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1