Ejemplo n.º 1
0
        public override void Execute(string collection, ref JObject item, ref Dictionary <string, object> dataContext)
        {
            if (collection == "_users")
            {
                if (dataContext.ContainsKey("NewPassword"))
                {
                    string  id = item["_id"].Value <string>();
                    JObject o  = new JObject
                    {
                        ["UserId"]       = id,
                        ["PasswordHash"] = RawUserStore.ComputePasswordHash(dataContext["NewPassword"] as string)
                    };

                    //Password cant' be changed during update
                    if (item.ContainsKey("_id") && !string.IsNullOrWhiteSpace(item["_id"].Value <string>()))
                    {
                        DataQuery query = new DataQuery()
                        {
                            RawQuery = JsonConvert.SerializeObject(new { UserId = id })
                        };

                        ItemList password = service.Query(collection, query);

                        if (password.Items.HasValues)
                        {
                            o["_id"] = password.Items[0]["_id"].Value <string>();
                            //patch password only
                            service.Update("_credentials", o, false);
                        }
                        else
                        {
                            service.Insert("_credentials", o);
                        }
                    }
                    else
                    {
                        service.Insert("_credentials", o);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public override void Execute(string collection, ref JObject item, ref Dictionary <string, object> dataContext)
 {
     if (collection == "_users")
     {
         if (item.ContainsKey("UserName"))
         {
             item["NormalizedUserName"] = RawUserStore.NormalizeString(item["UserName"].Value <string>());
         }
         if (item.ContainsKey("NormalizedEmail"))
         {
             item["NormalizedEmail"] = RawUserStore.NormalizeString(item["NormalizedEmail"].Value <string>());
         }
         if (item.ContainsKey("NewPassword"))
         {
             dataContext["NewPassword"] = item["NewPassword"].Value <string>();
             item.Remove("NewPassword");
         }
         if (item.ContainsKey("PasswordHash"))
         {
             item.Remove("PasswordHash");
         }
     }
 }
Ejemplo n.º 3
0
        public static IIdentityServerBuilder AddProfileServiceCustom(this IIdentityServerBuilder builder, RawUserStore instance)
        {
            builder.Services.AddTransient <IProfileService, RawUserStore>(x => { return(instance); });

            return(builder);
        }