Ejemplo n.º 1
0
 public ActionResult CreatePassword([FromBody] JObject credentialObj)
 {
     try
     {
         string emailId  = _commonClass.Decrypt(Convert.ToString(credentialObj["userId"]));
         string token    = (Convert.ToString(credentialObj["token"])).Replace(" ", "+");
         string password = Convert.ToString(credentialObj["password"]);
         if (!string.IsNullOrEmpty(token) && isLatestToken(token))
         {
             using (var userServices = new UserServices())
             {
                 int  resultCode = userServices.SetPassword(emailId, token, _commonClass.Encrypt(password));
                 bool isSuccess  = (resultCode == 200) ? true : false;
                 return(Ok(new { success = isSuccess, errorCode = resultCode }));//Password Created Successfully.
             }
         }
         else
         {
             string url      = HttpContext.Request.Headers["origin"];
             string newToken = GenerateEmailToken();
             using (var userServices = new UserServices())
             {
                 if (userServices.UpdateTokenInDatabase(emailId, token, newToken))
                 {
                     //Trigger confirm email for expired link
                     ConfirmPasswordEvent EmailEvent = new ConfirmPasswordEvent(_emailService, (url + "/createpassword/?token=" + newToken + "&uid=" + _commonClass.Encrypt(emailId)), Convert.ToInt32(_configuration["EmailLink:TimeToLiveHour"]), emailId, "en-us");
                     EmailEvent.Send();
                     return(Ok(new { success = false, errorCode = 204 }));//Link Expired Sent New Link.
                 }
                 else
                 {
                     return(Ok(new { success = false, errorCode = 203 }));//token or email provided wrong.
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message, null);
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 2
0
        public ActionResult RegisterNewUser(UserModel model)
        {
            try
            {
                using (var userService = new UserServices())
                {
                    model.Token = GenerateEmailToken();
                    int userId = userService.AddEditUser(model);
                    if (userId < 0)
                    {
                        return(Ok(new { success = false, errorCode = 201 }));//Email Address Allready Registerd.
                    }
                    try
                    {
                        string url = HttpContext.Request.Headers["origin"];
                        //Trigger usercreation email
                        UserCreationEvent emailEvent = new UserCreationEvent(_emailService, model.Email, model.Language_code);
                        emailEvent.Send();

                        //Trigger confirm email
                        ConfirmPasswordEvent EmailEvent = new ConfirmPasswordEvent(_emailService, (url + "/createpassword/?token=" + model.Token + "&uid=" + _commonClass.Encrypt(model.Email)), Convert.ToInt32(_configuration["EmailLink:TimeToLiveHour"]), model.Email, model.Language_code);
                        EmailEvent.Send();

                        return(Ok(new { success = true, errorCode = 200 }));//User Registered Successfully.
                    }
                    catch
                    {
                        return(Ok(new { success = false, errorCode = 202 }));//Error In Mail Sending
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message, null);
                return(BadRequest(ex.Message));
            }
        }