Beispiel #1
0
 private bool UserAlreadyExist(UserTbl userToRegister)
 {
     using (var context = new DBModels())
     {
         return(context.UserTbl.FirstOrDefault(x => x.Username == userToRegister.Username || x.Email == userToRegister.Email) != null);
     }
 }
Beispiel #2
0
        public string RegisterUser(UserTbl userToRegister)
        {
            string registerMessage;

            using (var context = new DBModels())
            {
                if (!UserAlreadyExist(userToRegister))
                {
                    context.UserTbl.Add(userToRegister);
                    context.SaveChanges();
                    registerMessage = UserMessages.UserRegisteredSuccesfully;
                }
                else
                {
                    registerMessage = UserMessages.DuplicateUser;
                }
            }
            return(registerMessage);
        }
Beispiel #3
0
        private void SendEmailResetCode(string resetCode, UserTbl userDetails)
        {
            try
            {
                var mail = new MailMessage
                {
                    // Set the to and from addresses.
                    // The from address must be your GMail account
                    From = new MailAddress("Email")
                };
                mail.To.Add(new MailAddress(userDetails.Email));

                // Define the message
                mail.Subject    = "Reset your eBar password";
                mail.IsBodyHtml = false;
                mail.Body       = "Dear " + userDetails.Name + @", \n\n" + "Your reset code is " + resetCode + @". The reset code is available only 24 hours.\n\n";

                // Create a new Smpt Client using Google's servers
                var mailclient = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,

                    // This is the critical part, you must enable SSL
                    EnableSsl = true,

                    // Specify your authentication details
                    Credentials = new NetworkCredential(
                        "Email",
                        "YourPassword!")
                };
                mailclient.Send(mail);
            }
            catch (Exception ex)
            {
                _logger.Log("SendEmailResetCode_Exception: ", ex.Message);
            }
        }