Esempio n. 1
0
        public IHttpActionResult SignUp(LoginDetailsViewModel login)
        {
            bool isValidEmail = comm.IsValidEmail(login.Email);

            if (!isValidEmail)
            {
                return(Content(HttpStatusCode.BadRequest, "Invalid Email address"));
            }

            if (!login.IsForgotPass)
            {
                String passErrMsg  = String.Empty;
                bool   isValidPass = comm.ValidatePassword(login.Password, out passErrMsg);
                if (!isValidPass)
                {
                    return(Content(HttpStatusCode.BadRequest, passErrMsg));
                }
            }

            try
            {
                //string pass = Membership.GeneratePassword(4, 0);
                string pass = login.Password;
                services.Common.PasswordCryptoService crypto = new services.Common.PasswordCryptoService();
                string encpass = crypto.EncryptText(pass);
                if (login.IsForgotPass)
                {
                    service.UpdatePass(new models.DatabaseTable.user
                    {
                        Email    = login.Email,
                        Username = login.Email,
                        Password = encpass
                    });
                }
                else
                {
                    service.Add(new models.DatabaseTable.user
                    {
                        Email       = login.Email,
                        Username    = login.Email,
                        Password    = encpass,
                        CreatedDate = DateTime.Now
                    });
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Esempio n. 2
0
 public int Add(user usr)
 {
     using (var db = new AppDb())
     {
         var checkuser = db.users.FirstOrDefault(f => f.Email == usr.Email);
         if (checkuser != null)
         {
             throw new Exception("User already exists, Click on forgot password for regenerate your password!");
         }
         services.Common.PasswordCryptoService crypto = new services.Common.PasswordCryptoService();
         usr.Password = crypto.EncryptText(usr.Password);
         db.users.Add(usr);
         var rec = db.SaveChanges();
         return(rec);
     }
 }