예제 #1
0
 public static AccountView Login(string email, string password)
 {
     try
     {
         db = new AceEntities();
         string  passHash = MD5_Sang.Encrypt(password);
         Account acc      = db.Account.SingleOrDefault(s => s.Email.Equals(email) && s.Password.Equals(passHash));
         if (acc != null)
         {
             return(new AccountView
             {
                 Id = acc.Id,
                 Email = acc.Email,
                 Address = acc.Address,
                 Name = acc.Name,
                 Password = acc.Password,
                 Phone = acc.Phone,
                 Role = (int)acc.Roles
             });
         }
         return(null);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
예제 #2
0
        public int Create(UserView userView)// thêm dữ liệu User
        {
            try
            {
                if (CheckExists(userView, db))
                {
                    return(-1);                           //check email, phone đã tồn tại chưa;
                }
                User user = new User
                {
                    Name        = userView.Name,
                    Email       = userView.Email,
                    Photo       = userView.Photo,
                    Address     = userView.Address,
                    Birthday    = userView.Birthday,
                    Gender      = (byte)userView.Gender,
                    Password    = MD5_Sang.Encrypt(userView.Password),
                    Phone       = userView.Password,
                    Role        = (byte)userView.Role,
                    DayCreate   = userView.DayCreate,
                    DayEdited   = userView.DayEdited,
                    Description = userView.Description,
                };

                db.User.Add(user);
                db.SaveChanges();
                return(user.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(0);
            }
        }
예제 #3
0
 public bool UpdatePassword(UserView userView)
 {
     try
     {
         User user = db.User.Find(userView.Id);
         user.Password = MD5_Sang.Encrypt(userView.Password);
         user.Forgotpw = null;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         return(false);
     }
 }
예제 #4
0
        public UserView LoginAdmin(UserView userView)
        {
            string passHash = MD5_Sang.Encrypt(userView.Password.Trim());

            return(db.User.AsNoTracking().Where(s => s.Email.ToLower().Trim() == userView.Email.ToLower().Trim() && s.Password == passHash && s.Role == 0 && s.Status && s.Active && s.Status).Select(s => new UserView
            {
                Id = s.Id,
                Email = s.Email,
                Name = s.Name,
                Phone = s.Phone,
                Address = s.Address,
                Photo = s.Photo,
                Birthday = (DateTime)s.Birthday,
                DayCreate = s.DayCreate,
                DayEdited = s.DayEdited,
                Gender = (byte)s.Gender,
                Role = s.Role,
                Description = s.Description
            }).SingleOrDefault());
        }
        public async Task <IActionResult> Login([FromBody] Account acc)
        {
            try
            {
                Account account = await db.Account.Where(s => s.Email.ToLower() == acc.Email.ToLower()).SingleOrDefaultAsync();

                if (account != null)
                {
                    if (MD5_Sang.VerifyMD5(acc.Password, account.Password))
                    {
                        return(Ok(new
                        {
                            Id = account.Id,
                            Name = account.Name,
                            Phone = account.Phone,
                            Address = account.Address,
                            Email = account.Email,
                            Roles = account.Roles,
                            Password = account.Password
                        }));
                    }
                    else
                    {
                        return(NotFound("Không tìm thấy"));
                    }
                }
                else
                {
                    return(NotFound("Không tìm thấy"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }