Esempio n. 1
0
        public IActionResult ResetPassword([FromBody] EmailDTO email)
        {
            if (email == null)
            {
                return(NotFound());
            }

            var user = contextUsers.Users.Find(email.Email);

            if (user == null || !user.IsActive)
            {
                return(NotFound());
            }

            Guid token = Guid.NewGuid();

            try
            {
                EmailManager.SendResetPasswordLinkEmail(email.Email, user.Name, token.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            SecurityLinkToken securityLinkToken = new SecurityLinkToken();

            securityLinkToken.Email  = email.Email;
            securityLinkToken.Token  = token.ToString();
            securityLinkToken.Type   = "resetpassword";
            securityLinkToken.IsDone = false;

            contextUsers.SecurityLinkTokens.Add(securityLinkToken);
            contextUsers.SaveChanges();


            return(Ok());
        }
Esempio n. 2
0
        public IActionResult RegisterUser([FromBody] RegisterUserDTO registerInfo)
        {
            if (registerInfo == null)
            {
                return(NotFound());
            }

            User user = contextUsers.Users.Find(registerInfo.Email);

            if (user != null && user.IsActive)
            {
                return(BadRequest("AlreadyExists"));
            }

            if (user == null)
            {
                user                  = new User();
                user.UserID           = registerInfo.Email;
                user.Name             = registerInfo.Name;
                user.Password         = registerInfo.Password;
                user.IsActive         = false;
                user.IsFirstLogon     = true;
                user.Role             = "user";
                user.CreationDateTime = DateTime.Now;
                contextUsers.Users.Add(user);
            }
            else
            {
                user.Name             = registerInfo.Name;
                user.Password         = registerInfo.Password;
                user.IsActive         = false;
                user.IsFirstLogon     = true;
                user.Role             = "user";
                user.CreationDateTime = DateTime.Now;
            }

            Guid token = Guid.NewGuid();

            try
            {
                EmailManager.SendActivationlinkEmail(registerInfo.Email, user.Name, token.ToString());
                EmailManager.SendSignUpNotificationEmail(EmailManager.AdminEmail, user.Name, user.UserID);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            SecurityLinkToken securityLinkToken = new SecurityLinkToken();

            securityLinkToken.Email            = registerInfo.Email;
            securityLinkToken.Token            = token.ToString();
            securityLinkToken.Type             = "activation";
            securityLinkToken.IsDone           = false;
            securityLinkToken.CreationDateTime = DateTime.Now;

            contextUsers.SecurityLinkTokens.Add(securityLinkToken);

            contextUsers.SaveChanges();
            return(Ok());
        }