Commit 8bf96c06 by Tuomas Riihimäki

Lisätty fileitä

1 parent 46b17589
No preview for this file type
No preview for this file type
package fi.insomnia.bortal.beans;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Date;
import javax.imageio.ImageIO;
import org.jbarcode.JBarcode;
import org.jbarcode.JBarcodeFactory;
import org.krysalis.barcode4j.BarcodeGenerator;
import org.krysalis.barcode4j.impl.code128.Code128Bean;
import org.krysalis.barcode4j.impl.datamatrix.DataMatrixBean;
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
import com.pdfjet.A4;
import com.pdfjet.Image;
import com.pdfjet.ImageType;
import com.pdfjet.IoStream;
import com.pdfjet.PDF;
import com.pdfjet.Page;
public class BarcodeBean {
public void barcode4j() throws FileNotFoundException, Exception {
long start = new Date().getTime();
File outFile = new File("/tmp/rairai2.pdf");
PDF pdf = new PDF(new FileOutputStream(outFile));
System.out.println("pre CreateCode: " + (new Date().getTime() - start));
BarcodeGenerator bean = new DataMatrixBean();
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.out.println("created: " + (new Date().getTime() - start));
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
out, "image/png", 150, BufferedImage.TYPE_BYTE_BINARY, false, 0);
bean.generateBarcode(canvas, "Foobar Rairai");
canvas.finish();
ByteArrayInputStream istream = new ByteArrayInputStream(out.toByteArray());
Image img = new Image(pdf, istream, ImageType.PNG);
Page page = new Page(pdf, A4.PORTRAIT);
img.drawOn(page);
System.out.println("post draw: " + (new Date().getTime() - start));
pdf.flush();
System.out.println("post flush: " + (new Date().getTime() - start));
}
public String asdasd() throws FileNotFoundException, Exception {
long start = new Date().getTime();
JBarcode code = JBarcodeFactory.getInstance().createCode128();
System.out.println("pre CreateCode: " + (new Date().getTime() - start));
BufferedImage barcode = code.createBarcode("Foobar Rairai");
System.out.println("created: " + (new Date().getTime() - start));
ImageIO.write(barcode, "JPEG", new File("/tmp/rairai.jpeg"));
System.out.println("To File: " + (new Date().getTime() - start));
File out = new File("/tmp/rairai2.pdf");
PDF pdf = new PDF(new FileOutputStream(out));
System.out.println("Pre stream: " + (new Date().getTime() - start));
ByteArrayOutputStream jpegstream = new ByteArrayOutputStream();
ImageIO.write(barcode, "JPEG", jpegstream);
System.out.println("post stream: " + (new Date().getTime() - start));
ByteArrayInputStream istream = new ByteArrayInputStream(jpegstream.toByteArray());
System.out.println("post istream: " + (new Date().getTime() - start));
Page page = new Page(pdf, A4.PORTRAIT);
Image img = new Image(pdf, istream, ImageType.JPEG);
img.drawOn(page);
System.out.println("post draw: " + (new Date().getTime() - start));
pdf.flush();
System.out.println("post flush: " + (new Date().getTime() - start));
return "";
}
public static void main(String[] args) {
BarcodeBean bb = new BarcodeBean();
try {
bb.barcode4j();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package fi.insomnia.bortal.beans;
import fi.insomnia.bortal.model.User;
public interface UtilBeanLocal {
boolean sendMail(User user, String subject, String message);
}
package fi.insomnia.bortal;
import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Bill;
public class asdasd {
/**
* @param args
*/
public static void main(String[] args) {
AccountEvent a = new AccountEvent();
Bill b = new Bill();
AccountEvent c = new AccountEvent();
System.out.println("A eq b " + a.equals(b));
System.out.println("A eq A " + a.equals(a));
System.out.println("B eq b " + b.equals(b));
System.out.println("B eq A " + b.equals(a));
System.out.println("C eq C " + c.equals(c));
System.out.println("A eq C " + a.equals(c));
System.out.println("C eq A " + c.equals(a));
}
}
package fi.insomnia.bortal.model;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.utilities.PasswordFunctions;
@MappedSuperclass
public class GenericEntity implements ModelInterface {
private static final Logger logger = LoggerFactory.getLogger(GenericEntity.class);
/**
*
*/
private static final long serialVersionUID = -9041737052951021560L;
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
@Override
public final boolean equals(Object object) {
if (!this.getClass().equals(object.getClass())) {
logger.debug("Classes dont match {} {}", getClass(), object.getClass());
return false;
}
GenericEntity other = (GenericEntity) object;
if (tempId != null && tempId.equals(other.tempId)) {
return true;
}
if (this.id == null) {
if (other.id != null) {
return false;
}
logger.debug("Ids are null. Resorting to randomidcheck!");
return getRandomId().equals(other.tempId);
}
return this.id.equals(other.id);
}
@Transient
private String tempId;
private String getRandomId() {
if (tempId == null) {
tempId = PasswordFunctions.generateRandomString(10);
}
return tempId;
}
@Override
public final int getJpaVersionField() {
return jpaVersionField;
}
@Override
public final void setJpaVersionField(int jpaVersionField) {
this.jpaVersionField = jpaVersionField;
}
@Override
public final int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : getRandomId().hashCode());
return hash;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
package fi.insomnia.bortal.model;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.utilities.PasswordFunctions;
@MappedSuperclass
public class GenericEventChild implements EventChildInterface {
private static final Logger logger = LoggerFactory.getLogger(GenericEventChild.class);
/**
*
*/
private static final long serialVersionUID = -9041737052951021560L;
@EmbeddedId
private EventPk id;
@Version
@Column(nullable = false)
private int jpaVersionField = 0;
@Override
public final boolean equals(Object object) {
if (!this.getClass().equals(object.getClass())) {
logger.debug("Classes dont match {} {}", getClass(), object.getClass());
return false;
}
GenericEventChild other = (GenericEventChild) object;
if(tempId != null && tempId.equals(other.tempId))
{
return true;
}
if (this.id == null) {
if (other.id != null) {
return false;
}
logger.debug("Ids are null. Resorting to randomidcheck!");
return getRandomId().equals(other.tempId);
}
return this.id.equals(other.id);
}
@Transient
private String tempId;
private String getRandomId() {
if (tempId == null) {
tempId = PasswordFunctions.generateRandomString(10);
}
return tempId;
}
@Override
public final EventPk getId() {
return id;
}
@Override
public final void setId(EventPk id) {
this.id = id;
}
@Override
public final int getJpaVersionField() {
return jpaVersionField;
}
@Override
public final void setJpaVersionField(int jpaVersionField) {
this.jpaVersionField = jpaVersionField;
}
@Override
public final int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : getRandomId().hashCode());
return hash;
}
}
package fi.insomnia.bortal.utilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.utilities.apachecodec.binary.Base64;
public class UglyFix {
// Don't touch. Fix old byte to String conversion bugs in passwords
private static final byte FIXSTR[] = { -17, -65, -67 };
private byte[] newarray;
private byte[] oldarray;
private int newint;
private int oldint;
private static final Logger logger = LoggerFactory.getLogger(UglyFix.class);
public UglyFix(String newBase64, String oldBase64) {
newint = 0;
oldint = 0;
newarray = Base64.decodeBase64(newBase64);
oldarray = Base64.decodeBase64(oldBase64);
}
public boolean check() {
boolean ret = true;
for (oldint = 0; oldint < oldarray.length && newint < newarray.length; ++oldint) {
if (oldarray[oldint] != newarray[newint]) {
logger.debug("No match checking against FIXSTR");
if (!checkForHITA()) {
logger.debug("hitacheck not ok. Returning false!");
ret = false;
break;
}
}
++newint;
}
return ret;
}
private boolean checkForHITA() {
boolean ret = false;
if (oldint + 3 < oldarray.length &&
oldarray[oldint] == FIXSTR[0] &&
oldarray[oldint + 1] == FIXSTR[1] &&
oldarray[oldint + 2] == FIXSTR[2]) {
logger.debug("FOUND hita string");
/*
* we have found the "hands in the air string" and thus skipped at
* least one newarray character, but maybe more.. So let's check.
*/
oldint = oldint + 3;
++newint;
for (int testnew = newint; testnew < newarray.length; ++testnew) {
logger.debug("checking char at newarray {} matches the character at oldarray:{}", newarray[testnew], oldarray[oldint]);
if (newarray[testnew] == oldarray[oldint]) {
ret = true;
break;
}
}
if (!ret && oldarray[oldint] == FIXSTR[0]) {
logger.debug("Recursive HITAcheck");
ret = checkForHITA();
}
}
return ret;
}
}
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:login="http://java.sun.com/jsf/composite/tools/login"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.auth.loginerror" />
<ui:define name="content">
<h1>#{i18n['passwordChanged.header']}</h1>
<p>
#{i18n['passwordChanged.body']}
</p>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:login="http://java.sun.com/jsf/composite/tools/login" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="/layout/${sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.auth.resetPassword" />
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="id" value="#{pwdResetView.id}" />
<f:viewParam name="hash" value="#{pwdResetView.hash}" />
</f:metadata>
</ui:define>
<ui:define name="content">
<h:form rendered="#{pwdResetView.hashMatch()}">
<h:inputHidden value="#{pwdResetView.user.id}" />
<h:panelGrid columns="3">
<h:outputLabel value="#{i18n['user.password']}:" for="password" />
<h:inputSecret id="password" value="#{pwdResetView.password}" />
<h:message for="password" />
<h:outputLabel value="#{i18n['user.passwordcheck']}:" for="passwordcheck" />
<h:inputSecret id="passwordcheck" value="#{pwdResetView.confirm}" />
<h:message for="passwordcheck" />
</h:panelGrid>
<h:commandButton id="changePassword" value="#{i18n['user.changePassword']}" action="#{pwdResetView.change()}" />
</h:form>
<h:outputText rendered="#{!pwdResetView.hashMatch() }" value="#{i18n['passwordReset.hashNotFound']}" />
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:login="http://java.sun.com/jsf/composite/tools/login"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.auth.loginerror" />
<ui:define name="content">
<h1>#{i18n['resetmailSent.header']}</h1>
<p>
#{i18n['resetmailSent.body']}
</p>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:login="http://java.sun.com/jsf/composite/tools/login" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="/layout/${sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.auth.resetPassword" />
<ui:define name="content">
<h1><h:outputText value="#{i18n['resetMail.header']}" /></h1>
<p><h:outputText value="#{i18n['resetMail.body']}" /></p>
<h:form>
<h:panelGrid columns="3">
<h:outputLabel value="#{i18n['resetMail.username']}:" for="username" />
<h:inputText id="username" value="#{pwdResetView.mailuser}" />
<h:message for="username" />
</h:panelGrid>
<h:commandButton id="sendReset" value="#{i18n['resetMail.send']}" action="#{pwdResetView.sendMail()}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.place.insertToken" />
<ui:define name="content">
<h1>#{i18n['placetoken.pageHeader']}</h1>
<p>#{i18n['placetoken.topText']}</p>
<h:form id="placeTokenForm">
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['placetoken.token']}:" />
<h:inputText value="#{placeGroupView.token}" />
<h:commandButton id="commitbtn" action="#{placeGroupView.saveToken()}" value="#{i18n['placetoken.commit']}" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.place.mygroups" />
<ui:define name="content">
#{placeGroupView.editSelf()}
<h:dataTable value="#{placeGroupView.groupMemberships}" var="member">
<h:column>
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{member.id.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="product" />
</f:facet>
<h:outputText value="#{member.placeReservation.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="token" />
</f:facet>
<h:outputText value="#{member.inviteToken}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="user" />
</f:facet>
<h:outputText value="#{member.user.login}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="creator" />
</f:facet>
<h:outputText value="#{member.placeGroup.creator.login}" />
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:map="http://java.sun.com/jsf/composite/tools/map" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.place.placemap" />
<ui:define name="content">
<h:form id="billform">
<h:panelGrid columns="2">
<h:outputText value="#{i18n['placemanagement.placeNameLike']}" /><h:inputText value="#{place}" />
<h:outputLabel for="paidDate" value="#{i18n['bill.paidDate']}:" />
<h:inputText id="paidDate" value="#{billManageView.bill.paidDate.time}">
<f:convertDateTime />
</h:inputText>
<h:outputLabel value="#{i18n['bill.billNumber']}:" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<p><input type="hidden" name="id" value="#{mapManageView.map.id.id}" /></p>
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['setBuyable.like']}" />
<h:inputText value="#{mapManageView.buyableLike}" />
<h:commandButton id="lockbtn" action="#{mapManageView.lockBuyable}" value="#{i18n['setBuyable.lock']}" />
<h:commandButton id="releasebtn" action="#{mapManageView.releaseBuyable}" value="#{i18n['setBuyable.release']}" />
</h:panelGrid>
</h:form>
</composite:implementation>
</html>
user.nickSizeMessage=Nimimerkin pit olla vhintn {min} merkki pitk.
user.emailregex=Kentss pit olla shkpostiosoite.
javax.validation.constraints.NotNull.message=Kentt ei saa olla tyhj
package fi.insomnia.bortal.view;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.beans.UserBeanLocal;
import fi.insomnia.bortal.model.User;
import fi.insomnia.bortal.utilities.PasswordFunctions;
@ManagedBean(name = "pwdResetView")
@SessionScoped
public class PasswordResetView extends GenericView {
private Integer id;
private String hash;
private static final Logger logger = LoggerFactory.getLogger(PasswordResetView.class);
private String password;
private String confirm;
private User user;
private String mailuser;
@EJB
private UserBeanLocal userbean;
public boolean hashMatch() {
if (id != null && id > 0 && hash != null && hash.length() > 5) {
user = userbean.findPasswordResetUser(id, hash);
}
return user != null;
}
public String change() {
boolean changed = false;
String ret = null;
if (password.length() < 5) {
addFaceMessage("userview.passwordTooShort");
} else if (!password.equals(confirm)) {
addFaceMessage("userview.passwordsDontMatch");
} else if (user != null) {
changed = userbean.resetPassword(user, password, hash);
}
if (changed)
ret = "passwordChanged";
return ret;
}
public String sendMail() {
User userObj = userbean.getUser(mailuser);
if (userObj != null) {
String hashStr = PasswordFunctions.generateRandomString(25);
ExternalContext extcontext = FacesContext.getCurrentInstance().getExternalContext();
StringBuilder path = new StringBuilder()
.append("http://")
.append(extcontext.getRequestServerName());
if (extcontext.getRequestServerPort() != 80) {
path.append(":").append(extcontext.getRequestServerPort());
}
path.append("/")
.append(FacesContext.getCurrentInstance().getExternalContext().getContextName())
.append("/auth/resetPassword.jsf?id=")
.append(userObj.getId()).append("&hash=")
.append(hashStr);
logger.debug("billpath {}", path);
userbean.initPasswordReset(userObj, hashStr, path.toString());
}
return "resetmailSent";
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getConfirm() {
return confirm;
}
public void setConfirm(String confirm) {
this.confirm = confirm;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public UserBeanLocal getUserbean() {
return userbean;
}
public void setUserbean(UserBeanLocal userbean) {
this.userbean = userbean;
}
public void setMailuser(String mailuser) {
this.mailuser = mailuser;
}
public String getMailuser() {
return mailuser;
}
}
No preview for this file type
No preview for this file type
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!