예제 #1
0
        public IHttpActionResult ResetPassword(SendActivationReq req)
        {
            try
            {
                string currentUsrEmail = HttpUtilities.GetUserNameFromToken(this.Request);
                byte[] salt            = AuthorizationUtilities.generateSalt();
                User   user            = _context.Users.FirstOrDefault(i => i.Id == req.UserId);
                //  if (user.IsActiveUser == false)
                ValidationUtilities.ValidateUserforNewPassword(req.UserId, user);

                string generatedPassword = AuthorizationUtilities.GeneratePassword();
                AuthorizationUtilities.SendPasswordtoUser(user.Email, generatedPassword);
                byte[] pwdhash = AuthorizationUtilities.hash(generatedPassword, user.Salt);
                //  user.Salt = salt;
                user.Password   = pwdhash;//AuthorizationUtilities.hash(generatedPassword, salt);
                user.ModifiedBy = currentUsrEmail;
                // user.UpdatedAt = DateTimeOffset.UtcNow;
                _context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
                return(Ok());
            }
            catch (HttpResponseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                LGSELogger.Error(ex);
                return(InternalServerError(ex));
            }
        }
예제 #2
0
        public IHttpActionResult ActivateUser(ActivationRequest request)
        {
            try
            {
                var dbUser = DbUtilities.GetUserByEmail(request.Email);
                if (dbUser != null)
                {
                    string validStatus = DbUtilities.ValidateForActivation(request, dbUser, false);
                    if (validStatus == Constants.SUCCESS_MSG)
                    {
                        //Need to get Oorg id based on domain
                        byte[] salt = AuthorizationUtilities.generateSalt();

                        User account = _context.Users.SingleOrDefault(a => a.Email == request.Email);
                        //    account.UpdatedAt = DateTime.UtcNow;
                        account.ModifiedBy  = request.Email;
                        account.Salt        = salt;
                        account.Password    = AuthorizationUtilities.hash(request.Password, salt);
                        account.IsActivated = true;
                        account.OTPCode     = "";
                        _context.SaveChanges();
                        return(Ok(HttpUtilities.CustomResp(ErrorCodes.USER_ACTIVATED.ToString())));
                    }
                    else
                    {
                        return(BadRequest(validStatus));
                    }
                }
                else
                {
                    return(BadRequest(ErrorCodes.INVALID_USER.ToString()));
                }
            }
            catch (Exception ex)
            {
                LGSELogger.Error(ex);
                return(InternalServerError(ex));
            }
        }