public async Task <HttpResponseMessage> Get(string emailId, string siteurl)
        {
            try
            {
                var manager = Request.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var user    = manager.FindByEmail(emailId);

                if (manager.FindById(user.Id) == null || user == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found"));
                }

                var provider = new CustomAuthorizationServerProvider();
                var token    = await manager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = siteurl + "/Account/EmailConfirmed?UserId=" + System.Web.HttpUtility.UrlEncode(user.Id) + "&token=" + System.Web.HttpUtility.UrlEncode(token);

                await manager.SendEmailAsync(user.Id.ToString(), "Confirm your account", "Please confirm your account by clicking : <a href='http://" + callbackUrl + "'>link</a>");

                return(Request.CreateResponse(HttpStatusCode.OK, callbackUrl, "application/json"));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
示例#2
0
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            var myProvider = new CustomAuthorizationServerProvider();
            OAuthAuthorizationServerOptions options = new OAuthAuthorizationServerOptions
            {
                // For Dev environment only (on production should be AllowInsecureHttp = false)
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(30),
                Provider = myProvider
            };

            app.UseOAuthAuthorizationServer(options);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            HttpConfiguration config = new HttpConfiguration();

            WebApiConfig.Register(config);
            GlobalConfiguration.Configuration.Filters.Add(new CheckNullAttribute());
            GlobalConfiguration.Configuration.Filters.Add(new ValidateModelStateAttribute());
        }