Beispiel #1
0
        public async Task <IActionResult> Register([FromBody] RegisterUserRequest registerUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
            }

            var user = new IdentityUser
            {
                UserName       = registerUser.Email,
                Email          = registerUser.Email,
                EmailConfirmed = true
            };

            var result = await _userManager.CreateAsync(user, registerUser.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            // Add roles to new user
            await _userManager.AddToRoleAsync(user, IdentityRoles.GetRole(registerUser.AccessType));

            await _signInManager.SignInAsync(user, false);

            return(Ok(await CreateJwt(registerUser.Email)));
        }
Beispiel #2
0
        public override global::System.Data.DataSet Clone()
        {
            IdentityRoles cln = ((IdentityRoles)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Beispiel #3
0
        public ActionResult Edit([Bind(Include = "id,title")] IdentityRoles userGroup)
        {
            if (ModelState.IsValid)
            {
                repository.Update(userGroup);

                return(RedirectToAction("Index"));
            }
            return(View(userGroup));
        }
 public void Update(IdentityRoles userGroup)
 {
     using (UspaIdentityDb db = new UspaIdentityDb())
     {
         if (userGroup != null)
         {
             db.Entry(userGroup).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
     }
 }
Beispiel #5
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            IdentityRoles ds = new IdentityRoles();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
        public void Delete(string id)
        {
            using (UspaIdentityDb db = new UspaIdentityDb())
            {
                IdentityRoles deleteUserGroup = db.IdentityRoles.FirstOrDefault(ug => ug.Id.Equals(id));

                if (deleteUserGroup != null)
                {
                    db.Entry(deleteUserGroup).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                }
            }
        }
Beispiel #7
0
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IdentityRoles userGroups = repository.GetById(id);

            if (userGroups == null)
            {
                return(HttpNotFound());
            }
            return(View(userGroups));
        }
        public void Add(IdentityRoles newUserGroup)
        {
            using (UspaIdentityDb db = new UspaIdentityDb())
            {
                var UserManager = new UserManager <User>(new UserStore <User>(db));


                if (newUserGroup != null)
                {
                    db.IdentityRoles.Add(newUserGroup);
                    db.SaveChanges();
                }
            }
        }
Beispiel #9
0
        private async static Task SeedIdentityRoles(IServiceProvider services)
        {
            using (IServiceScope scope = services.CreateScope())
            {
                RoleManager <IdentityRole> roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();

                foreach (string role in IdentityRoles.GetAll())
                {
                    bool roleExists = await roleManager.RoleExistsAsync(role);

                    if (!roleExists)
                    {
                        await roleManager.CreateAsync(new IdentityRole(role));
                    }
                }
            }
        }
Beispiel #10
0
        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return(false);
            }

            var role = (string)value;

            if (string.IsNullOrEmpty(role))
            {
                return(false);
            }

            var roles = IdentityRoles.GetRoles();

            return(roles.Any(r => r.Equals(role, StringComparison.InvariantCultureIgnoreCase)));
        }
        public async Task <IActionResult> Post([FromBody] AuthenticationDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var responseDto = await Envelope(async() =>
            {
                var result   = await _identityService.Authenticate(dto.Username, dto.Password);
                var response = TokenResponseDto.Create(result, dto.Username);

                if (result == AuthenticateResult.Ok)
                {
                    var identity = await _identityRepository.GetByEmail(dto.Username);
                    var claims   = new[]
                    {
                        new Claim(JwtRegisteredClaimNames.Sub, identity.Id.ToString()),
                        new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                        new Claim(ClaimTypes.Email, identity.Email),
                        new Claim(ClaimTypes.Name, identity.Username),
                        new Claim(ClaimTypes.Actor, identity.IdType.ToString()),
                        new Claim(ClaimTypes.Role, IdentityRoles.ToRole(identity.IdType))
                    };

                    var token = new JwtSecurityToken(
                        _configurationProvider.TokenConfiguration.Issuer,
                        _configurationProvider.TokenConfiguration.Audience,
                        claims,
                        expires: DateTime.UtcNow.AddHours(1),
                        signingCredentials: new SigningCredentials(
                            _configurationProvider.TokenConfiguration.SigningKey,
                            SecurityAlgorithms.HmacSha256));

                    response.Token = new JwtSecurityTokenHandler().WriteToken(token);
                }

                return(response);
            });

            responseDto.IsSuccessful = responseDto.Payload.Token.HasValue();
            return(Ok(responseDto));
        }
Beispiel #12
0
        public static async Task CreateRoles(IServiceProvider serviceProvider, IConfiguration configuration, IOptions <IdentitySettings> identitySettings)
        {
            // adding custom roles
            var            roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            var            userManager = serviceProvider.GetRequiredService <UserManager <IdentityUser> >();
            IdentityResult roleResult;

            foreach (var role in IdentityRoles.GetRoles())
            {
                // creating the roles and seeding them to the database
                var roleExist = await roleManager.RoleExistsAsync(role);

                if (!roleExist)
                {
                    roleResult = await roleManager.CreateAsync(new IdentityRole(role));
                }
            }

            // creating a super user who could maintain the web app
            var powerUser = new IdentityUser
            {
                UserName       = identitySettings.Value.SuperUser.Name,
                Email          = identitySettings.Value.SuperUser.Email,
                EmailConfirmed = true
            };

            string userPassword = identitySettings.Value.SuperUser.Password;

            var user = await userManager.FindByEmailAsync(identitySettings.Value.SuperUser.Email);

            if (user == null)
            {
                var createPowerUser = await userManager.CreateAsync(powerUser, userPassword);

                if (createPowerUser.Succeeded)
                {
                    // here we tie new user to the "Admin" role
                    await userManager.AddToRoleAsync(powerUser, IdentityRoles.Admin);
                }
            }
        }
Beispiel #13
0
 public Task<List<IdentityRole>> AllRolesAsync()
 {
     return IdentityRoles.Find(r => true).ToListAsync();
 }
Beispiel #14
0
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                IdentityRoles ds = new IdentityRoles();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "DataTable1DataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }