Exemplo n.º 1
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            try
            {
                var identity  = new ClaimsIdentity(context.Options.AuthenticationType);
                var dbContext = new AppNetEntities();
                var result    = dbContext.Auftraggeber
                                .Any(u => u.UserName == context.UserName && u.PasswordHash == context.Password);

                if (context.UserName == "admin" && context.Password == "admin")
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
                    identity.AddClaim(new Claim("username", "admin"));
                    identity.AddClaim(new Claim(ClaimTypes.Name, "Anton Markaj"));
                    context.Validated(identity);
                }
                else if (result)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
                    var firstname = dbContext.Auftraggeber
                                    .Where(u => u.UserName == context.UserName && u.PasswordHash == context.Password).FirstOrDefault().vorname;

                    var lastname = dbContext.Auftraggeber
                                   .Where(u => u.UserName == context.UserName && u.PasswordHash == context.Password).FirstOrDefault().nachname;

                    var username = dbContext.Auftraggeber
                                   .Where(u => u.UserName == context.UserName && u.PasswordHash == context.Password).FirstOrDefault().UserName;

                    identity.AddClaim(new Claim(ClaimTypes.Name, firstname + " " + lastname));
                    identity.AddClaim(new Claim("username", username));
                    context.Validated(identity);

                    Console.WriteLine("Login granted to user \"" + username + "\"");

                    /* identity.AddClaim(new Claim("username", "user"));
                     * identity.AddClaim(new Claim(ClaimTypes.Name, "Alfred Sopi"));
                     * context.Validated(identity);*/
                }
                else
                {
                    context.SetError("invalid_grant", "Provided username or password is incorrect!");
                    Console.WriteLine("Login failed: Wrong username or password");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
 public HttpResponseMessage RegisterAuftraggeber([FromBody] Auftraggeber auftraggeber)
 {
     using (var context = new AppNetEntities())
     {
         try {
             context.Auftraggeber.Add(auftraggeber);
             context.SaveChanges();
             HttpResponseMessage response = Request.CreateResponse(System.Net.HttpStatusCode.Created);
             return(response);
         }
         catch (Exception ex)
         {
             HttpResponseMessage response = Request.CreateResponse(System.Net.HttpStatusCode.NotFound);
             Console.WriteLine(ex.Message);
             return(response);
         }
     }
 }
Exemplo n.º 3
0
 public HttpResponseMessage PostYourOffer([FromBody] Offerte offerte)
 {
     using (var context = new AppNetEntities())
     {
         try
         {
             context.Offerte.Add(offerte);
             context.SaveChanges();
             HttpResponseMessage response = Request.CreateResponse(System.Net.HttpStatusCode.Created);
             return(response);
         }
         catch (Exception ex)
         {
             HttpResponseMessage response = Request.CreateResponse(System.Net.HttpStatusCode.NotFound);
             Console.WriteLine(ex.Message);
             return(response);
         }
     }
 }
Exemplo n.º 4
0
        public IEnumerable <Offerte> GetReceivedOffers(string sortBy, int auftragsnummer)
        {
            try
            {
                var context = new AppNetEntities();

                var result = context.Offerte
                             .Where(a => a.auftragsNummer == auftragsnummer)
                             .OrderBy(sortBy + " ASC")
                             .Select(a => a);

                return(result.ToList());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 5
0
        public IEnumerable <Offerte> GetYourOffers(string sortBy, int userId)
        {
            try
            {
                var context = new AppNetEntities();

                var result = context.Offerte
                             .Where(a => a.userid == userId)
                             .OrderBy(sortBy + " ASC")
                             .Select(a => a);

                return(result.ToList());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 6
0
        // GET: api/ausschreibung?sortBy&userId
        public IEnumerable <Auftrag> GetYourPublishedOrders(string sortBy, int userId)
        {
            try
            {
                var context = new AppNetEntities();

                var result = context.Auftrag
                             .Where(a => a.Id == userId)
                             .Where(a => a.ausgeschrieben == true)
                             .OrderBy(sortBy + " ASC")
                             .Select(a => a);

                return(result.ToList());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Exemplo n.º 7
0
        public Auftraggeber getAuftraggeberProfil(int userid)
        {
            var profile = new AppNetEntities().Auftraggeber.Where(u => u.Id == userid).SingleOrDefault();

            return(profile);
        }
Exemplo n.º 8
0
        public IEnumerable <Auftrag> Get()
        {
            var dbContext = new AppNetEntities();

            return(dbContext.Auftrag.ToList());
        }