Ejemplo n.º 1
0
        public PotentialUserComponent(Guid potentialUserId)
        {
            if (potentialUserId != Guid.Empty)
            {
                mifnexsoEntities = new MIFNEXSOEntities();
                try
                {
                    potentialUser = mifnexsoEntities.PotentialUsers.FirstOrDefault(a => a.PotentialUserId == potentialUserId);


                    if (potentialUser == null)
                    {
                        potentialUser = new PotentialUser();
                        potentialUser.PotentialUserId = Guid.Empty;

                        mifnexsoEntities.PotentialUsers.AddObject(potentialUser);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                potentialUser = new PotentialUser();
            }
        }
Ejemplo n.º 2
0
        public PotentialUserComponent(string email)
        {
            if (!string.IsNullOrEmpty(email))
            {
                mifnexsoEntities = new MIFNEXSOEntities();
                try
                {
                    potentialUser = mifnexsoEntities.PotentialUsers.FirstOrDefault(a => a.Email == email && (a.Deleted == false || a.Deleted == null));


                    if (potentialUser == null)
                    {
                        potentialUser                 = new PotentialUser();
                        potentialUser.Email           = email;
                        potentialUser.PotentialUserId = Guid.Empty;

                        mifnexsoEntities.PotentialUsers.AddObject(potentialUser);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                potentialUser = new PotentialUser();
            }
        }
Ejemplo n.º 3
0
        public ActionResult PotentialUser(PotentialUser pu, string referrerUrl, string ghRole)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    pu.Role = ghRole;

                    if (pu.PotentialUserID > 0)
                    {
                        _trs.UpdatePotentialUser(pu);
                    }
                    else
                    {
                        _trs.SavePotentialUser(pu);
                    }

                    //if (string.IsNullOrEmpty(referrerUrl))
                    return(RedirectToAction("PotentialUsers", "Account"));
                    //else
                    //    return Redirect(referrerUrl);
                }

                return(View(pu));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(new HttpStatusCodeResult(500));
            }
        }
        public IMaybe <Jwt.TokenBundle> MaybeLogin(PotentialUser potentialUser)
        {
            var maybeUser = _userRepository.MaybeGetOne(potentialUser.Username);

            return(maybeUser.Case(
                       some: user =>
            {
                var isUsersAccountDisabled = !user.IsActive;
                if (isUsersAccountDisabled)
                {
                    return None <Jwt.TokenBundle> .Exists;
                }

                var isPasswordCorrect = PasswordService.Validate(potentialUser.Password, user.Password);
                if (!isPasswordCorrect)
                {
                    return None <Jwt.TokenBundle> .Exists;
                }

                var sesssion = _sessionCommand.Execute(new SessionCommand.Create(
                                                           user: user,
                                                           startedOn: DateTime.Now
                                                           ));

                return Some <Jwt.TokenBundle> .Exists(new Jwt.TokenBundle(
                                                          bearerToken: new Jwt.BearerToken(username: user.Username, role: user.Role),
                                                          refreshToken: new Jwt.RefreshToken(id: sesssion.Id, startedOn: sesssion.StartedOn)
                                                          ));
            },
                       none: () => None <Jwt.TokenBundle> .Exists));
        }
Ejemplo n.º 5
0
        public PotentialUserComponent()
        {
            mifnexsoEntities = new MIFNEXSOEntities();
            potentialUser    = new PotentialUser();
            potentialUser.PotentialUserId = Guid.Empty;

            mifnexsoEntities.PotentialUsers.AddObject(potentialUser);
        }
Ejemplo n.º 6
0
 public string GenerateTokenForPotentialUser(PotentialUser pu)
 {
     try
     {
         return(Crypto.Hash(pu.Name + pu.Email));
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         return(null);
     }
 }
Ejemplo n.º 7
0
 public void DeletePotentialUser(PotentialUser pu)
 {
     try
     {
         _pur.Delete(pu);
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         throw ex;
     }
 }
Ejemplo n.º 8
0
 public void Delete(PotentialUser pu)
 {
     try
     {
         db.Entry(pu).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         throw ex;
     }
 }
Ejemplo n.º 9
0
 public void Save(PotentialUser pu)
 {
     try
     {
         db.PotentialUsers.Add(pu);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         throw ex;
     }
 }
Ejemplo n.º 10
0
        public void UpdatePotentialUser(PotentialUser pu)
        {
            try
            {
                pu.Token = GenerateTokenForPotentialUser(pu);

                _pur.Update(pu);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                throw ex;
            }
        }
        public PotentialUser Add(PotentialUserDto potentialUserDto)
        {
            var potentialUser = new PotentialUser
            {
                Id         = Guid.NewGuid(),
                UserCode   = potentialUserDto.UserCode,
                FirstName  = potentialUserDto.FirstName,
                LastName   = potentialUserDto.LastName,
                UserRoleId = potentialUserDto.RoleId,
                Email      = potentialUserDto.Email
            };

            _repository.Insert(potentialUser);
            _repository.Save();

            return(potentialUser);
        }
Ejemplo n.º 12
0
        private void InsertAdmin(PotentialUser potentialUser)
        {
            var role = _repository.GetByFilter <UserRole>(x => x.Id == potentialUser.UserRoleId);

            if (role.Name == "Admin")
            {
                var admin = new Admin
                {
                    Id              = Guid.NewGuid(),
                    LastName        = potentialUser.LastName,
                    FirstName       = potentialUser.LastName,
                    PotentialUserId = potentialUser.Id
                };

                _repository.Insert(admin);
                _repository.Save();
            }
        }
Ejemplo n.º 13
0
        public ActionResult PotentialUser(long?id)
        {
            try
            {
                if (Request.UrlReferrer != null)
                {
                    ViewBag.referrerUrl = Request.UrlReferrer.AbsoluteUri;
                }

                var potentialUser = new PotentialUser();
                if (id != null && id > 0)
                {
                    potentialUser = _trs.FindPotentialUser((long)id);
                }

                return(View(potentialUser));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(HttpNotFound());
            }
        }