Пример #1
0
        public void RecoverPassword(string email)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(email))
                {
                    throw new System.Exception("failed");
                }
                else
                {
                    var user = _db.Users.First(u => u.Email.Equals(email));

                    TokenLogic TokenLogic = new TokenLogic(_db);
                    string     token      = TokenLogic.UpdateToken(user.UserId, user.Email, user.Password);

                    SendRecoverEmail(token, user.FirstName, user.Email);
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #2
0
        /// <summary>
        /// Adaugare utilizator
        /// </summary>
        /// <param name="userDTO"></param>
        /// <returns></returns>
        public bool AddUser(Users userDTO)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(userDTO.Password) || string.IsNullOrWhiteSpace(userDTO.Email))
                {
                    throw new System.Exception("failed");
                }
                else
                {
                    // Adauga un user
                    MD5    md5        = new MD5CryptoServiceProvider();
                    byte[] textToHash = Encoding.Default.GetBytes(userDTO.Password);
                    byte[] result     = md5.ComputeHash(textToHash);
                    string passHash   = BitConverter.ToString(result);

                    userDTO.Password = passHash;

                    var x = _db.Users.Add(userDTO);
                    _db.SaveChanges();
                    var userId = _db.Users.First(u => u.Email.Equals(userDTO.Email)).UserId;

                    TokenLogic TokenLogic = new TokenLogic(_db);
                    string     token      = TokenLogic.UpdateToken(userId, userDTO.Email, userDTO.Password);

                    // Trimitere mai verificare
                    SendAuthEmail(token, userDTO.FirstName, userDTO.Email);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="objDataAccess"></param>
 public AuthLogic(GHContext context)
 {
     _db        = context;
     TokenLogic = new TokenLogic(context);
 }