Android Open Source - innovativeproject-meetingdataexchange Accounts






From Project

Back to project page innovativeproject-meetingdataexchange.

License

The source code is released under:

MIT License

If you think the Android project innovativeproject-meetingdataexchange listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package controllers;
/* w w  w  .  jav  a  2s .  c om*/
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jooq.Record;
import org.jooq.Record2;

import models.DbSingleton;
import static models.Tables.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
import tools.MD5Checksum;

public class Accounts extends Controller {

  public static Result register(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");
    else{
      String login = json.findPath("login").textValue();
      String name = json.findPath("name").textValue();
      String email = json.findPath("email").textValue();
      String password = json.findPath("password").textValue();
      
      
      return ok(web_register(login, name, email, password));
    }
  }
  
  public static ObjectNode web_register(String login, String name, String email, String password){
    if(login == null)
      return errorObject("incorrect login");
    if(!checkEmail(email) || email == null)
      return errorObject("incorrect email");
    if(name == null)
      return errorObject("incorrect name");
    if(password == null)
      return errorObject("incorrect password");
    
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl().select().from(USER)
              .where(USER.LOGIN.equal(login)).fetch();
    
    if(record.isNotEmpty())
      return errorObject("Login already exists");
    
    DbSingleton.getInstance().getDsl()
        .insertInto(USER,
            USER.LOGIN, USER.NAME, USER.EMAIL, USER.PASSWORD)
        .values(login, name, email, MD5Checksum.MD5(password)).execute();

    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    return result;
  }
  
  public static Result login(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");

    String login = json.findPath("login").textValue();
    String password = json.findPath("password").textValue();
    return ok(web_login(login, password));
  }
  
  public static ObjectNode web_login(String login, String password){
    if(login == null || password == null)
      return errorObject("incorrect data");

    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl().select().from(USER).where(USER.LOGIN.equal(login))
        .and(USER.PASSWORD.equal(MD5Checksum.MD5(password))).fetch();
    if(record.isNotEmpty()){
      String hash = new BigInteger(130, new SecureRandom()).toString(32);
      
      DbSingleton.getInstance().getDsl().insertInto(SESSION,
          SESSION.USERLOGIN, SESSION.SID)
          .values(login, hash).execute();
      ObjectNode result = Json.newObject();
      result.put("status", "ok");
      result.put("sid", hash);
      return result;
    }
    else
      return errorObject("incorrect data");
  }
  
  public static Result logoff(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");
    String login = json.findPath("login").textValue();
    String sid = json.findPath("sid").textValue();
    return ok(web_logoff(login, sid));
  }
  
  public static ObjectNode web_logoff(String login, String sid){
    if(login == null || sid == null)
      return errorObject("incorrect data");

    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl().select().from(SESSION)
        .where(SESSION.USERLOGIN.equal(login)).and(SESSION.SID.equal(sid)).fetch();
    if(record.isNotEmpty()){
      DbSingleton.getInstance().getDsl().delete(SESSION).where(SESSION.USERLOGIN.equal(login)).and(SESSION.SID.equal(sid)).execute();
      ObjectNode result = Json.newObject();
      result.put("status", "ok");
      return result;
    }
    else
      return errorObject("incorrect sid");
  }
  
  public static Result getData(String login, String sid){
    return ok(web_getData(login,sid));
  }
  
  public static ObjectNode web_getData(String login, String sid){
    if(login==null || sid==null)
      return errorObject("incorrect data");
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    
    org.jooq.Result<Record2<String, String>> record = DbSingleton.getInstance().getDsl()
        .select(USER.NAME, USER.EMAIL)
        .from(USER)
        .where(USER.LOGIN.equal(login)).fetch();
    
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    result.put("name", record.getValue(0, USER.NAME));
    result.put("email", record.getValue(0, USER.EMAIL));
    
    return result;
  }
  
  public static Result setData(){
    JsonNode json = request().body().asJson();
    if(json == null)
      return errorResult("json excepted");
    
    String login = json.findPath("login").textValue();
    String sid = json.findPath("sid").textValue();
    String email = json.findPath("email").textValue();
    String name = json.findPath("name").textValue();
    String password = json.findPath("password").textValue();
    
    return ok(web_setData(login,sid, email, name, password));
  }
  
  public static ObjectNode web_setData(String login, String sid, String email, String name, String password){
    if(login==null || sid==null)
      return errorObject("incorrect data");
    if(!checkIsSidCorrect(login, sid))
      return errorObject("incorrect sid");
    
    if(email != null){
      if(!checkEmail(email))
        return errorObject("incorrect email");
      
      DbSingleton.getInstance().getDsl().update(USER)
        .set(USER.EMAIL, email)
        .where(USER.LOGIN.equal(login)).execute();
    }
    
    if(name != null){
      DbSingleton.getInstance().getDsl().update(USER)
        .set(USER.NAME, name)
        .where(USER.LOGIN.equal(login)).execute();
    }
    
    if(password != null){
      DbSingleton.getInstance().getDsl().update(USER)
        .set(USER.PASSWORD, MD5Checksum.MD5(password))
        .where(USER.LOGIN.equal(login)).execute();
    }
    
    ObjectNode result = Json.newObject();
    result.put("status", "ok");
    return result;
  }

  
  private static Result errorResult(String msg) {
    return ok(errorObject(msg));
  }
  
  private static ObjectNode errorObject(String msg){
    ObjectNode result = Json.newObject();
    result.put("status", "failed");
    result.put("reason", msg);
    return result;
  }
  
  private static boolean checkEmail(String email) {
    final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
        + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    Pattern pattern = Pattern.compile(EMAIL_PATTERN);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
  }

  private static boolean checkIsSidCorrect(String login, String sid) {
    org.jooq.Result<Record> record = DbSingleton.getInstance().getDsl().select().from(SESSION)
        .where(SESSION.USERLOGIN.equal(login)).and(SESSION.SID.equal(sid)).fetch();
        if(record.isNotEmpty())
          return true;  
        else
          return false;
  }
  
}




Java Source Code List

Dialogs.ServerOptionsLoggedIn.java
Dialogs.ServerOptionsLoggedOut.java
asynctasks.HttpGetListMeetings.java
asynctasks.HttpGetPersonalData.java
asynctasks.HttpGetServerName.java
asynctasks.HttpPostNewMeeting.java
asynctasks.HttpPostRequestLogInAlreadyExistsUser.java
asynctasks.HttpPostRequestLogInFirstTime.java
asynctasks.HttpPostRequestLogIn.java
asynctasks.HttpPostSignUp.java
asynctasks.HttpPutSendFile.java
asynctasks.RefreshMeetingProgress.java
com.TrololoCompany.meetingdataexchangeAdapters.FileAdapter.java
com.TrololoCompany.meetingdataexchangeAdapters.MeetingAdapter.java
com.TrololoCompany.meetingdataexchangeAdapters.ServerAdapter.java
com.TrololoCompany.meetingdataexchange.AddNewMeetingActivity.java
com.TrololoCompany.meetingdataexchange.AddServerActivityFail.java
com.TrololoCompany.meetingdataexchange.AddServerActivitySuccess.java
com.TrololoCompany.meetingdataexchange.AddServerActivity.java
com.TrololoCompany.meetingdataexchange.DisplayQR.java
com.TrololoCompany.meetingdataexchange.LogInActivity.java
com.TrololoCompany.meetingdataexchange.MainActivity.java
com.TrololoCompany.meetingdataexchange.MeetingDetails.java
com.TrololoCompany.meetingdataexchange.ServerList.java
com.TrololoCompany.meetingdataexchange.ServerManageActivity.java
com.TrololoCompany.meetingdataexchangeServices.MeetingDetailsRefresh.java
com.TrololoCompany.meetingdataexchangeServices.MeetingServerCommunication.java
com.TrololoCompany.meetingdataexchangeServices.ServiceHandlers.java
com.TrololoCompany.meetingdataexchange.SignUpActivity.java
com.TrololoCompany.meetingdataexchange.util.SystemUiHiderBase.java
com.TrololoCompany.meetingdataexchange.util.SystemUiHiderHoneycomb.java
com.TrololoCompany.meetingdataexchange.util.SystemUiHider.java
com.TrololoCompany.meetingdataexchangedataBase.CommentEntity.java
com.TrololoCompany.meetingdataexchangedataBase.DataBaseHelper.java
com.TrololoCompany.meetingdataexchangedataBase.FileEntity.java
com.TrololoCompany.meetingdataexchangedataBase.MeetingEntity.java
com.TrololoCompany.meetingdataexchangedataBase.ServerEntity.java
controllers.Accounts.java
controllers.FilesManagement.java
controllers.GeneralStuff.java
controllers.Mailing.java
controllers.Meetings.java
dataBase.CommentEntity.java
dataBase.DataBaseHelper.java
dataBase.FileEntity.java
dataBase.MeetingEntity.java
dataBase.MettingEntity.java
dataBase.ServerEntity.java
dataBase.Server.java
fileMaintenance.FileMaintenance.java
lists.MeetingList.java
lists.ServerList.java
meeting_options.FireMissilesDialogFragment.java
meeting_options.MeetDetOnPageListener.java
meeting_options.MeetDetTabListener.java
meeting_options.MeetingAddItems.java
meeting_options.MeetingDescription.java
meeting_options.MeetingProgressUIRefresh.java
meeting_options.MeetingProgress.java
meeting_options.MeetingTabPagerAdapter.java
meeting_options.MyOnPageChangeListener.java
meeting_options.MyTabListener.java
meeting_options.RefreshMeetingProgressListView.java
meeting_options.TabsPagerAdapter.java
models.DbSingleton.java
models.DefaultSchema.java
models.Keys.java
models.Tables.java
models.tables.Comment.java
models.tables.File.java
models.tables.Meeting.java
models.tables.Meetinguser.java
models.tables.Session.java
models.tables.SqliteSequence.java
models.tables.User.java
models.tables.records.CommentRecord.java
models.tables.records.FileRecord.java
models.tables.records.MeetingRecord.java
models.tables.records.MeetinguserRecord.java
models.tables.records.SessionRecord.java
models.tables.records.SqliteSequenceRecord.java
models.tables.records.UserRecord.java
serverCommunicator.CheckIsServerExists.java
serverCommunicator.CommentsHelper.java
serverCommunicator.CommunicationHelper.java
serverCommunicator.Communication.java
serverCommunicator.FileHelper.java
serverCommunicator.FileListRefreshService.java
serverCommunicator.GetMeetingListHelper.java
serverCommunicator.GetPersonalDataHelper.java
serverCommunicator.HttpGetRequest.java
serverCommunicator.HttpPostRequest.java
serverCommunicator.LogInHelper.java
serverCommunicator.MeetingHelper.java
serverCommunicator.NewMeetingHelper.java
serverCommunicator.RegistrationHelper.java
tools.MD5Checksum.java