public IHttpActionResult UpdateProfil([FromBody] USER user)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.USERS.FirstOrDefault(x => x.Id == id);
                    if (result == null)
                    {
                        return(BadRequest());
                    }
                    else
                    {
                        PassManagement ps      = new PassManagement();
                        byte[]         salt    = ps.Hashing(user.Mail);
                        string         hashing = ps.HashPass(user.Hash, salt);
                        result.Hash        = hashing;
                        result.Mail        = user.Mail;
                        result.UpdatedDate = DateTime.Now;
                        result.UserName    = user.UserName;
                        result.Name        = user.Name;
                        int save = db.SaveChanges();
                        if (save != 0)
                        {
                            return(Ok());
                        }
                        else
                        {
                            return(BadRequest());
                        }
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
示例#2
0
 public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
 {
     context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
     using (MynoteDBEntities db = new MynoteDBEntities())
     {
         PassManagement pm      = new PassManagement();
         byte[]         salt    = pm.Hashing(context.UserName);
         string         hashing = pm.HashPass(context.Password, salt);
         var            user    = db.USERS.Where(x => x.Mail == context.UserName && x.Hash == hashing).
                                  Select(x => new { x.Id, x.Name, x.Mail, x.RegisterDate, x.UserName, x.UserImage }).ToList();
         if (user.Count == 0)
         {
             context.SetError("oturum_hatası", "Mail adresi veya şifre hatalı.");
         }
         else
         {
             var user1    = user.FirstOrDefault();
             var idendity = new ClaimsIdentity(context.Options.AuthenticationType);
             idendity.AddClaim(new Claim("Sid", Convert.ToString(user1.Id)));
             context.Validated(idendity);
         }
     }
 }
 public IHttpActionResult RegisterUser(USER model)
 {
     if (model == null)
     {
         return(BadRequest("Geçersiz kullanıcı"));
     }
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         PassManagement ps      = new PassManagement();
         byte[]         salt    = ps.Hashing(model.Mail);
         string         hashing = ps.HashPass(model.Hash, salt);
         model.Hash         = hashing;
         model.RegisterDate = DateTime.Now;
         using (MynoteDBEntities ent = new MynoteDBEntities())
         {
             ent.USERS.Add(model);
             int result = ent.SaveChanges();
             if (result != 0)
             {
                 return(Ok("Kullanıcı başarıyla kaydedilmiştir"));
             }
             else
             {
                 return(BadRequest("Kullanıcı kaydı başarısız"));
             }
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }