Exemplo n.º 1
0
        public void Update(TakeDocModel.UserTk user, TakeDocModel.Entity entity, TakeDocModel.Version version, Newtonsoft.Json.Linq.JObject jsonDocument, Newtonsoft.Json.Linq.JArray jsonMetadata, bool startWorkflow)
        {
            TakeDocModel.Document document = daoDocument.GetBy(x => x.DocumentCurrentVersionId == version.VersionId).First();

            if (jsonDocument != null && jsonDocument.Value <string>("label") != null)
            {
                this.SetTitle(jsonDocument.Value <string>("label"), version.VersionId, user.UserTkId, entity.EntityId);
            }
            if (jsonMetadata != null)
            {
                servMeta.SetMetaData(user.UserTkId, document, entity, startWorkflow, jsonMetadata);
            }

            bool ok = true;

            try
            {
                ok = servMeta.BeProven(document, document.LastVersionMetadata);
            }
            catch (Exception ex) { ok = false; }

            if (jsonDocument != null && ok == true)
            {
                servStatus.SetStatus(document, TakeDocModel.Status_Document.Complete, user.UserTkId, true);
            }
            if (startWorkflow)
            {
                if (ok == false)
                {
                    throw new Exception("MetaData non valide.");
                }
                this.StartWorkflow(document, user, entity.EntityId, false);
            }
        }
Exemplo n.º 2
0
        private void FillField(TakeDocModel.Version version, TakeDocModel.Entity entity, FileInfo destination)
        {
            TakeDocModel.UserTk user = daoUser.GetBy(x => x.UserTkId == version.Document.DocumentOwnerId).First();

            string directoryEntity = string.Concat(TakeDocModel.Environnement.ModelDirectory, entity.EntityReference);

            ICollection <TakeDocModel.Dto.Document.ReadOnlyMetadata> roMetaDatas = servMetaData.GetReadOnlyMetaData(version);

            ULibre.Drivers.Interface.IDriver model = new ULibre.Drivers.Implementation.OdtDriver();
            model.Open(destination.FullName);

            foreach (TakeDocModel.Dto.Document.ReadOnlyMetadata ro in roMetaDatas.OrderBy(x => x.DisplayIndex))
            {
                if (ro.Type.ToUpper().Equals("IMAGE") == true)
                {
                    model.FillImageBase64(ro.Name, ro.Value);
                }
                else
                {
                    model.FillField(ro.Name, ro.Label);
                }
            }

            ICollection <string> title = new List <string>();

            title.Add("Titre");
            title.Add(version.Document.DocumentLabel);
            if (model.Exists("TabMetadata"))
            {
                model.AddLine("TabMetadata", title.ToArray <string>());
                ICollection <string> reference = new List <string>();
                reference.Add("Référence doc.");
                reference.Add(version.Document.DocumentReference);
                model.AddLine("TabMetadata", reference.ToArray <string>());
                foreach (TakeDocModel.Dto.Document.ReadOnlyMetadata ro in roMetaDatas.OrderBy(x => x.DisplayIndex))
                {
                    ICollection <string> line = new List <string>();
                    line.Add((string.IsNullOrEmpty(ro.Label) ? string.Empty : ro.Label));
                    line.Add((string.IsNullOrEmpty(ro.Text) ? string.Empty : servTraduction.Get("fr", ro.Text)));
                    if (ro.Type.ToUpper().Equals("IMAGE") == false)
                    {
                        model.AddLine("TabMetadata", line.ToArray <string>());
                    }
                }
                model.RemoveEmptyLine("TabMetadata");
            }

            FileInfo logo = new FileInfo(string.Concat(directoryEntity, @"\images\Logo.png"));

            if (logo.Exists)
            {
                model.FillImage("Logo", logo.FullName);
            }

            model.FillField("TypeDocument", version.Document.Type_Document.TypeDocumentLabel);
            model.FillField("Entite", entity.EntityLabel);
            model.FillField("Consultant", string.Concat(user.UserTkFirstName, " ", user.UserTkLastName));

            model.Save();
        }
Exemplo n.º 3
0
 public HttpResponseMessage UpdateUserTk(Guid userId, string firstName, string lastName, string email, string culture, bool enable, bool activate, Guid groupId, Guid?managerId)
 {
     try
     {
         TakeDocService.Security.Interface.IUserTkService servUser = Utility.MyUnityHelper.UnityHelper.Resolve <TakeDocService.Security.Interface.IUserTkService>();
         ICollection <TakeDocModel.UserTk> users = servUser.GetBy(x => x.UserTkId == userId);
         if (users.Count != 1)
         {
             throw new Exception("Invalid user");
         }
         TakeDocModel.UserTk user = users.First();
         user.UserTkFirstName = firstName;
         user.UserTkLastName  = lastName;
         user.UserTkEmail     = email;
         user.UserTkCulture   = culture;
         user.UserTkEnable    = enable;
         user.UserTkActivate  = activate;
         user.UserTkGroupId   = groupId;
         user.UserTkManagerId = managerId;
         servUser.Update(user);
         return(Request.CreateResponse(HttpStatusCode.OK, true));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Exemplo n.º 4
0
        public void ChangePassword(Guid userId, string olderPaswword, string newPassword)
        {
            using (System.Transactions.TransactionScope tr = new System.Transactions.TransactionScope())
            {
                ICollection <TakeDocModel.UserTk> users = this.GetBy(x => x.UserTkId == userId);
                if (users.Count != 1)
                {
                    base.CreateError("L'utilisateur est iconnu.");
                }

                TakeDocModel.UserTk user = users.First();
                // check older password
                if (user.UserTkPassword != servCrypto.Encrypt(olderPaswword))
                {
                    this.CreateError("Mot de passe erronné.");
                }
                user.UserTkPassword = servCrypto.Encrypt(newPassword);
                this.Check(user, false);

                // update password
                daoUserTk.Update(user);

                tr.Complete();
            }
        }
Exemplo n.º 5
0
        public ICollection <TakeDocModel.UserTk> GetByName(Guid userId, string name)
        {
            TakeDocModel.UserTk user = daoUserTk.GetBy(x => x.UserTkId == userId).First();
            ICollection <TakeDocModel.UserTk> users = this.GetBy(x => x.UserTkLastName.StartsWith(name) || x.UserTkFirstName.StartsWith(name));

            return(users);
        }
Exemplo n.º 6
0
        public TakeDocModel.UserTk Logon(string login, string password)
        {
            this.Logger.InfoFormat("Log on {0}", login);
            TakeDocModel.UserTk user = this.GetByLogin(login);
            var passwordDecrypt      = servCrypto.Decrypt(user.UserTkPassword);

            if (user != null && (password != passwordDecrypt || user.UserTkEnable == false || user.UserTkActivate == false))
            {
                user = null;
            }
            if (user == null)
            {
                string msg = string.Format("Utilisateur inconnu ou non identifié : {0}", login);
                this.Logger.Info(msg);
                throw new Exception(msg);
            }

            TakeDocModel.RefreshToken token = servToken.CreateRefreshToken(user.UserTkId, "Logon");

            user.RefreshToken      = token.Id;
            user.RefreshTokenTicks = token.DateEndUTC.Value.Ticks;
            user.AccessToken       = token.AccessToken.First().Id;
            user.AccessTokenTicks  = token.AccessToken.First().DateEndUTC.Value.Ticks;

            return(user);
        }
Exemplo n.º 7
0
        public bool IsValidAccessToken(Guid accessTokenId, string[] accessGroup)
        {
            base.Logger.DebugFormat("Test access token {0} date", accessTokenId);
            // test if token is valid
            ICollection <TakeDocModel.AccessToken> accessTokens = daoAccessToken.GetBy(x => x.Id == accessTokenId &&
                                                                                       x.DateStartUTC <= System.DateTime.UtcNow &&
                                                                                       System.DateTime.UtcNow <= x.DateEndUTC);

            if (accessTokens.Count() > 1)
            {
                return(false);
            }
            if (accessTokens.Count() <= 0)
            {
                return(false);
            }
            base.Logger.DebugFormat("Test access token  {0} has valid date", accessTokenId);
            base.Logger.DebugFormat("Test access token  {0} group", accessTokenId);
            if (accessGroup.Count() == 1 && accessGroup[0] == string.Empty)
            {
                return(true);
            }

            TakeDocModel.AccessToken current = accessTokens.First();
            TakeDocModel.UserTk      user    = daoUserTk.GetBy(x => x.UserTkId == current.ClientId, x => x.GroupTk).First();
            if (accessGroup.Contains(user.GroupTk.GroupTkReference) == false)
            {
                base.Logger.DebugFormat("no access for {0} token because is invalid group access", accessTokenId);
                return(false);
            }
            base.Logger.DebugFormat("Test access token  {0} group is valid", accessTokenId);

            return(true);
        }
Exemplo n.º 8
0
        public void RemoveUser(Guid userId, Guid entityId)
        {
            TakeDocModel.Entity entity = daoEntity.GetBy(x => x.EntityId == entityId).First();
            TakeDocModel.UserTk user   = daoUser.GetBy(x => x.UserTkId == userId).First();

            daoEntity.RemoveUser(user, entity);
        }
Exemplo n.º 9
0
 public bool Execute(TakeDocModel.Document document, TakeDocModel.UserTk user)
 {
     this.SetStatus(document, TakeDocModel.Status_Document.ToValidate, user.UserTkId);
     base.SetTypeDocumentValidation(document, "BACKOFFICE", 0);
     daoDocument.Update(document);
     servReportVersion.Generate(document.DocumentCurrentVersionId.Value, document.EntityId);
     return(true);
 }
Exemplo n.º 10
0
 public void Delete(Guid userId, Guid currentUserId)
 {
     using (System.Transactions.TransactionScope tr = new System.Transactions.TransactionScope())
     {
         TakeDocModel.UserTk user = daoUserTk.GetBy(x => x.UserTkId == userId).First();
         daoUserTk.Delete(user);
         context.AddEvent("REMOVE_USER", "UserTkService.Delete", string.Format("userId : {0} login : {1} by currentUserId {2}", userId, user.UserTkLogin, currentUserId));
         tr.Complete();
     }
 }
Exemplo n.º 11
0
        private void StartWorkflow(TakeDocModel.Document document, TakeDocModel.UserTk user, Guid entityId, bool checkValue)
        {
            bool ok = true;

            if (checkValue)
            {
                TakeDocModel.Version version = servVersion.GetById(document.DocumentCurrentVersionId.Value, x => x.MetaData);
                ok = servMeta.BeProven(document, version.MetaData);
                // here, all metadata are ok, so document is complete
                servStatus.SetStatus(document, TakeDocModel.Status_Document.Complete, user.UserTkId, true);
            }
            if (ok)
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    //***********************************
                    // update status of document
                    //***********************************
                    TakeDocModel.WorkflowType validation = document.Type_Document.WorkflowType;

                    TakeDocService.Workflow.Document.Interface.IValidation wfValidation = null;
                    if (validation.WorkflowTypeReference == "AUTO")
                    {
                        wfValidation = new TakeDocService.Workflow.Document.ValidationAuto();
                        wfValidation.Execute(document, user);
                    }
                    else if (validation.WorkflowTypeReference == "NO")
                    {
                        wfValidation = new TakeDocService.Workflow.Document.ValidationNo();
                        wfValidation.Execute(document, user);
                    }
                    else if (validation.WorkflowTypeReference == "MANAGER")
                    {
                        wfValidation = new TakeDocService.Workflow.Document.ValidationManager();
                        wfValidation.Execute(document, user);
                    }
                    else if (validation.WorkflowTypeReference == "BACKOFFICE")
                    {
                        wfValidation = new TakeDocService.Workflow.Document.ValidationBackOffice();
                        wfValidation.Execute(document, user);
                    }
                    else if (validation.WorkflowTypeReference == "MANAGER-BACKOFFICE")
                    {
                        wfValidation = new TakeDocService.Workflow.Document.ValidationManagerBackOffice();
                        wfValidation.Execute(document, user);
                    }

                    //***********************************
                    // end update status of document
                    //***********************************

                    transaction.Complete();
                }
            }
        }
Exemplo n.º 12
0
 public bool Execute(TakeDocModel.Document document, TakeDocModel.UserTk user)
 {
     TakeDocModel.Version version = document.LastVersion;
     servReportVersion.Generate(version.VersionId, version.EntityId);
     this.SetStatus(document, TakeDocModel.Status_Document.Approve, user.UserTkId);
     if (this.daoWorkflow.IsAllApprove(version.VersionId, version.EntityId))
     {
         this.SetStatus(document, TakeDocModel.Status_Document.Archive, user.UserTkId);
     }
     return(true);
 }
Exemplo n.º 13
0
        private void SendMailAccountEnable(TakeDocModel.UserTk user)
        {
            string title    = daoParameter.GetBy(x => x.ParameterReference == "MAIL_ACTIVATE_ACCOUNT_TITLE").First().ParameterValue;
            string bodyFile = daoParameter.GetBy(x => x.ParameterReference == "MAIL_ACTIVATE_ACCOUNT_BODY").First().ParameterValue;
            string from     = daoParameter.GetBy(x => x.ParameterReference == "MAIL_ACTIVATE_ACCOUNT_FROM").First().ParameterValue;

            string path = string.Concat(TakeDocModel.Environnement.ModelDirectory, "MASTER", @"\", "mail", @"\", bodyFile);
            string body = System.IO.File.ReadAllText(path);

            servMail.Send(title, body, from, user.UserTkEmail, user);
        }
Exemplo n.º 14
0
        private void SendMailNewPassword(TakeDocModel.UserTk user)
        {
            string title    = daoParameter.GetBy(x => x.ParameterReference == "MAIL_NEW_PASSWORD_TITLE").First().ParameterValue;
            string bodyFile = daoParameter.GetBy(x => x.ParameterReference == "MAIL_NEW_PASSWORD_BODY").First().ParameterValue;
            string from     = daoParameter.GetBy(x => x.ParameterReference == "MAIL_NEW_PASSWORD_FROM").First().ParameterValue;

            string entityRef = "MASTER";
            string path      = string.Concat(TakeDocModel.Environnement.ModelDirectory, entityRef, @"\", "mail", @"\", bodyFile);
            string body      = System.IO.File.ReadAllText(path);

            servMail.Send(title, body, from, user.UserTkEmail, user);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Format data in object
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 private TakeDocModel.UserTk Format(TakeDocModel.UserTk user)
 {
     user.UserTkLastName = user.UserTkLastName.ToUpper();
     if (user.UserTkFirstName.Length >= 2)
     {
         user.UserTkFirstName = user.UserTkFirstName.Substring(0, 1).ToUpper() + user.UserTkFirstName.Substring(1).ToLower();
     }
     else
     {
         user.UserTkFirstName = user.UserTkFirstName.ToUpper();
     }
     return(user);
 }
Exemplo n.º 16
0
 public HttpResponseMessage GetById(Guid userId)
 {
     try
     {
         TakeDocService.Security.Interface.IUserTkService servUser = Utility.MyUnityHelper.UnityHelper.Resolve <TakeDocService.Security.Interface.IUserTkService>();
         TakeDocModel.UserTk user = servUser.GetBy(x => x.UserTkId == userId).First();
         return(Request.CreateResponse(HttpStatusCode.OK, string.Concat(user.UserTkFirstName, " ", user.UserTkLastName)));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Exemplo n.º 17
0
        public HttpResponseMessage Logon([FromBody] string value)
        {
            IUserTkService servUser = UnityHelper.Resolve <IUserTkService>();

            Newtonsoft.Json.Linq.JObject data = Newtonsoft.Json.Linq.JObject.Parse(value);
            try
            {
                TakeDocModel.UserTk user = servUser.Logon(data.Value <string>("login"), data.Value <string>("password"));
                return(Request.CreateResponse(HttpStatusCode.OK, user));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 18
0
        public TakeDocModel.UserTk GetByLogin(string login)
        {
            ICollection <TakeDocModel.UserTk> users = this.GetBy(x => x.UserTkLogin == login, x => x.GroupTk);

            if (users.Count() > 1)
            {
                base.CreateError(string.Format("Le login {0} ne peut pas exister plusileurs fois.", login));
            }
            else if (users.Count() == 0)
            {
                base.CreateError(string.Format("Utilisateur {0} inconu.", login));
            }
            TakeDocModel.UserTk user = users.First();

            return(user);
        }
Exemplo n.º 19
0
        public ClaimsPrincipal GetClaimsPrincipal(TakeDocModel.UserTk user)
        {
            ICollection <Claim> claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.Email, user.UserTkEmail));
            claims.Add(new Claim(ClaimTypes.Name, user.UserTkLastName));
            claims.Add(new Claim(ClaimTypes.GivenName, user.UserTkFirstName));
            claims.Add(new Claim("ExternalAccount", user.UserTkExternalAccount.ToString()));
            claims.Add(new Claim("Reference", user.UserTkReference));
            claims.Add(new Claim("Login", user.UserTkLogin));
            claims.Add(new Claim("Id", user.UserTkId.ToString()));

            ClaimsIdentity ci = new ClaimsIdentity(claims);

            return(new ClaimsPrincipal(ci));
        }
Exemplo n.º 20
0
        public HttpResponseMessage GetUser(Guid userId)
        {
            IUserTkService servUser = UnityHelper.Resolve <IUserTkService>();

            try
            {
                ICollection <TakeDocModel.UserTk> users = servUser.GetBy(x => x.UserTkId == userId);
                TakeDocModel.UserTk user = users.First();

                return(Request.CreateResponse(HttpStatusCode.OK, user));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 21
0
        public void Update(TakeDocModel.UserTk user)
        {
            using (System.Transactions.TransactionScope tr = new System.Transactions.TransactionScope())
            {
                user.UserTkLogin = user.UserTkEmail;
                this.Check(user, false);
                user = this.Format(user);
                // we stored the first time when account is enable
                if (user.UserTkEnable == true && user.UserTkDateFirstEnable == null)
                {
                    user.UserTkDateFirstEnable = System.DateTime.UtcNow;
                    this.SendMailAccountEnable(user);
                }
                daoUserTk.Update(user);

                tr.Complete();
            }
        }
Exemplo n.º 22
0
        public string GenerateNewPassword(Guid userId)
        {
            string newPassWord = System.Web.Security.Membership.GeneratePassword(7, 0);

            ICollection <TakeDocModel.UserTk> users = this.GetBy(x => x.UserTkId == userId);

            if (users.Count != 1)
            {
                base.CreateError("L'utilisateur est iconnu.");
            }
            TakeDocModel.UserTk user = users.First();

            user.UserTkPassword = servCrypto.Encrypt(newPassWord);
            daoUserTk.Update(user);

            this.SendMailNewPassword(user);

            return(newPassWord);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Send mail to inform that a user ask a account
        /// </summary>
        /// <param name="user">user who want to create account</param>
        /// <param name="entity"></param>
        private void SendMailToInform(TakeDocModel.UserTk user, TakeDocModel.Entity entity)
        {
            string toParameter = string.Concat("MAIL_INFORM_REQUEST_ACCOUNT_TO_", entity.EntityReference);
            ICollection <TakeDocModel.Parameter> parameters = daoParameter.GetBy(x => x.ParameterReference == toParameter);

            if (parameters.Count() == 0)
            {
                throw new Exception("Aucun destinataire ne sera informé dans cette demande. Votre demande ne sera pas prise en compte.");
            }

            string to       = parameters.First().ParameterValue;
            string from     = daoParameter.GetBy(x => x.ParameterReference == "MAIL_INFORM_REQUEST_ACCOUNT_FROM").First().ParameterValue;
            string title    = daoParameter.GetBy(x => x.ParameterReference == "MAIL_INFORM_REQUEST_ACCOUNT_TITLE").First().ParameterValue;
            string bodyFile = daoParameter.GetBy(x => x.ParameterReference == "MAIL_INFORM_REQUEST_ACCOUNT_BODY").First().ParameterValue;

            string path = string.Concat(TakeDocModel.Environnement.ModelDirectory, entity.EntityReference, @"\", "mail", @"\", bodyFile);
            string body = System.IO.File.ReadAllText(path);

            servMail.Send(title, body, from, to, user);
        }
Exemplo n.º 24
0
        public bool CreateRequest(string firstName, string lastName, string email, string password, string culture, string entityRef)
        {
            bool back = false;

            using (System.Transactions.TransactionScope tr = new System.Transactions.TransactionScope())
            {
                ICollection <TakeDocModel.Entity> entitys = daoEntity.GetBy(x => x.EntityReference == entityRef);
                if (entitys.Count() == 0)
                {
                    base.CreateError("Entity unknow");
                }
                Guid entityId            = entitys.First().EntityId;
                TakeDocModel.UserTk user = new TakeDocModel.UserTk()
                {
                    UserTkFirstName = firstName,
                    UserTkLastName  = lastName,
                    UserTkEmail     = email,
                    UserTkLogin     = email,
                    UserTkPassword  = password,
                    UserTkCulture   = culture,
                    UserTkExterneId = null,
                    UserTkActivate  = false,
                    GroupTk         = servGroupe.GetBy(x => x.GroupTkReference == "USER").First()
                };
                try
                {
                    servUser.Create(user, entitys.First());
                    this.SendMailToInform(user, entitys.First());

                    back = true;
                    tr.Complete();
                }
                catch (Exception ex)
                {
                    this.Logger.Error(ex);
                    back = false;
                    throw ex;
                }
            }
            return(back);
        }
Exemplo n.º 25
0
        public bool ActivateUser(string userRef)
        {
            bool back = false;
            ICollection <TakeDocModel.UserTk> users = servUser.GetBy(x => x.UserTkReference == userRef);

            if (users.Count != 1)
            {
                base.CreateError(string.Format("L'utilisateur {0} n'existe pas.", userRef));
            }

            TakeDocModel.UserTk user = users.First();
            if (user.UserTkActivate == true)
            {
                base.CreateError(string.Format("Utilisateur {0} déjà activé", user.UserTkLogin));
            }

            user.UserTkActivate = true;
            servUser.Update(user);

            return(back);
        }
Exemplo n.º 26
0
        public TakeDocModel.RefreshToken CreateRefreshToken(Guid clientId, string source)
        {
            int durationRefresh = Convert.ToInt32(daoParameter.GetBy(x => x.ParameterReference == "REFRESH_TOKEN_DURATION").First().ParameterValue);

            TakeDocModel.RefreshToken refresh = new TakeDocModel.RefreshToken();
            TakeDocModel.UserTk       user    = daoUserTk.GetBy(x => x.UserTkId == clientId).First();

            refresh.Id           = System.Guid.NewGuid();
            refresh.ClientId     = clientId;
            refresh.DateStartUTC = System.DateTime.UtcNow;
            refresh.DateEndUTC   = System.DateTime.UtcNow.AddSeconds(durationRefresh);
            refresh.Source       = source;
            refresh.Role         = user.GroupTk.GroupTkId;

            daoRefreshToken.Context.RefreshToken.Add(refresh);
            daoRefreshToken.Context.SaveChanges();

            this.GetNewAccessToken(clientId, refresh.Id, refresh.Role, refresh.Id, source);

            return(refresh);
        }
Exemplo n.º 27
0
        private TakeDocModel.UserTk Create(TakeDocModel.UserTk user)
        {
            // encrypt password
            user.UserTkPassword = servCrypto.Encrypt(user.UserTkPassword);

            bool isValid = this.Check(user, true);

            user = this.Format(user);
            user.UserTkEnable = false;

            try
            {
                return(daoUserTk.Create(user));
            }
            catch (Exception ex)
            {
                string msg = string.Format("Error creation user name : {0} {1} - email : {2} - password : {3}", user.UserTkFirstName, user.UserTkLastName, user.UserTkEmail, user.UserTkPassword);
                this.Logger.Error(ex);
                base.CreateError(msg);
                return(null);
            }
        }
Exemplo n.º 28
0
        public void Update(Guid userId, Guid entityId, string json, bool startWorkflow)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                Newtonsoft.Json.Linq.JArray  data      = Newtonsoft.Json.Linq.JArray.Parse(json);
                Newtonsoft.Json.Linq.JObject context   = String.IsNullOrEmpty(data[0].ToString()) ? null : (Newtonsoft.Json.Linq.JObject)data[0];
                Newtonsoft.Json.Linq.JObject document  = String.IsNullOrEmpty(data[1].ToString()) ? null : (Newtonsoft.Json.Linq.JObject)data[1];
                Newtonsoft.Json.Linq.JArray  metadatas = String.IsNullOrEmpty(data[2].ToString()) ? null : (Newtonsoft.Json.Linq.JArray)data[2];
                Newtonsoft.Json.Linq.JArray  pages     = String.IsNullOrEmpty(data[3].ToString()) ? null : (Newtonsoft.Json.Linq.JArray)data[3];
                Guid versionId = new Guid(document.Value <string>("versionId"));

                TakeDocModel.Entity  entity  = daoEntity.GetBy(x => x.EntityId == entityId).First();
                TakeDocModel.Version version = servVersion.GetById(versionId);
                TakeDocModel.UserTk  user    = daoUser.GetBy(x => x.UserTkId == userId).First();

                if (pages != null)
                {
                    servPage.Update(pages, userId, version, entity.EntityId);
                }
                servDocument.Update(user, entity, version, document, metadatas, startWorkflow);
                transaction.Complete();
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Add/enable manager validation for this document
 /// </summary>
 /// <param name="user"></param>
 protected void SetManagerValidation(TakeDocModel.Document document, TakeDocModel.UserTk currentUser, string workflowType, int step)
 {
     if (document.DocumentCurrentVersionId.Value == Guid.Empty || document.DocumentCurrentVersionId.Value == null)
     {
         throw new Exception("Version can't be empty.");
     }
     if (currentUser.UserTkManagerId == Guid.Empty || currentUser.UserTkManagerId == null)
     {
         throw new Exception("Manager can't be empty.");
     }
     TakeDocModel.Workflow workflow = new TakeDocModel.Workflow();
     workflow.WorkflowId               = Guid.NewGuid();
     workflow.EntityId                 = document.EntityId;
     workflow.WorkflowVersionId        = document.DocumentCurrentVersionId.Value;
     workflow.WorkflowIndex            = step;
     workflow.WorkflowAnswerId         = null;
     workflow.WorkflowTypeId           = daoWorkflowType.GetBy(x => x.WorkflowTypeReference == workflowType).First().WorkflowTypeId;
     workflow.WorkflowUserId           = currentUser.UserTkManagerId;
     workflow.WorkflowStatusDocumentId = document.DocumentStatusId;
     workflow.EtatDeleteData           = false;
     workflow.DateCreateData           = System.DateTimeOffset.UtcNow;
     daoWorkflow.Add(workflow);
 }
Exemplo n.º 30
0
        /// <summary>
        /// Check user data
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private bool Check(TakeDocModel.UserTk user, bool createMode)
        {
            bool emailExist = false;

            /*
             * createMode is true : verify if a user with this email exist,
             * createMode is false : verify if a user, not the current, with this email exist
             */
            if (createMode)
            {
                emailExist = (this.GetBy(x => x.UserTkEmail == user.UserTkEmail).Count() > 0);
            }
            else
            {
                emailExist = (this.GetBy(x => x.UserTkEmail == user.UserTkEmail && x.UserTkId != user.UserTkId).Count() > 0);
            }

            bool validPassword = servCrypto.Decrypt(user.UserTkPassword).Length >= 5;

            if (emailExist == true)
            {
                base.CreateError("Cette adresse mail est déjà utilisée.");
            }
            if (validPassword == false)
            {
                base.CreateError("Votre mot de passe doit avoir au moins 5 caractères.");
            }

            bool isEmail = Regex.IsMatch(user.UserTkEmail, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

            if (isEmail == false)
            {
                base.CreateError(string.Format("Création d'un utilisateur : cette adresse mail n'est pas valide {0}", user.UserTkEmail));
            }

            return(true);
        }