Exemplo n.º 1
0
        public async Task <ActionResult> cemail()
        {
            var json     = new StreamReader(Request.Body).ReadToEnd();
            var userInfo = JsonConvert.DeserializeObject <ApplicationUser>(json);

            if (userInfo.isadmin)
            {
                // Admin Version
                if (userInfo.Id != null && userInfo.Id != "")
                {
                    if (userInfo.Email != "" && userInfo.Email.Contains("@"))
                    {
                        UserBLL.Update_Field_Id(_context, userInfo.Id, "email", userInfo.Email);
                        return(Ok(new { status = "success", message = SiteConfig.generalLocalizer["_record_updated"].Value }));
                    }
                    else
                    {
                        return(Ok(new { status = "success", message = SiteConfig.generalLocalizer["_invalid_email"].Value }));
                    }
                }
                else
                {
                    return(Ok(new { status = "error", message = SiteConfig.generalLocalizer["_no_records"].Value }));
                }
            }
            else
            {
                // My Account Version
                var result = await _signInManager.PasswordSignInAsync(userInfo.UserName, userInfo.password, false, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    // generate own validation key
                    string val_key = Guid.NewGuid().ToString().Substring(0, 10);
                    // update user validation key
                    UserBLL.Update_Field_UserName(_context, userInfo.UserName, "val_key", val_key);

                    var URL = Config.GetUrl() + "login/changeemail?user="******"&code=" + val_key;
                    await _emailSender.ChangeEmailResetAsync(_context, userInfo.Email, userInfo.UserName, URL);

                    return(Ok(new { status = "success", message = SiteConfig.generalLocalizer["_confirmation_mail_sent"].Value }));
                }
                else
                {
                    return(Ok(new { status = "success", message = SiteConfig.generalLocalizer["_authentication_failed"].Value }));
                }
            }
        }