public ActionResult Register(User regUser)
        {
            var dbUser = new tblperson();

            if (AuthManager.CheckIfEmailIsUnique(regUser.Email))
            {
                dbUser.firstname       = regUser.Firstname;
                dbUser.lastname        = regUser.Lastname;
                dbUser.gamertag        = regUser.Gamertag;
                dbUser.email           = regUser.Email;
                dbUser.password        = regUser.Password;
                dbUser.salt            = regUser.Salt;
                dbUser.userrole        = "user";
                dbUser.currencybalance = 1000;
                dbUser.isactive        = true;

                AuthManager.Register(dbUser);

                TempData["confRegister"] = "Registration complete!";
                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["failRegister"] = "Emailadress is allready in use!";
                return(RedirectToAction("Register"));
            }
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "idperson,firstname,lastname,gamertag,currencybalance,isactive,email,password,salt,userrole")] tblperson tblperson)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblperson).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tblperson));
 }
        /// <summary>
        /// Get 1 User based on an ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns>tblPerson</returns>
        public static tblperson GetUserByIdAdmin(int id)
        {
            tblperson ReturnUser = null;

            using (var db = new ClonestoneFSEntities())
            {
                ReturnUser = db.tblperson.Where(u => u.idperson == id).FirstOrDefault();
            }
            return(ReturnUser);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblperson tblperson = db.tblperson.Find(id);

            if (tblperson == null)
            {
                return(HttpNotFound());
            }
            return(View(tblperson));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get User role based on email adress
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static string GetRoleByUserEmail(string email)
        {
            string role = "";

            using (var db = new ClonestoneFSEntities())
            {
                tblperson dbUser = db.tblperson.Where(u => u.email == email).FirstOrDefault();
                if (dbUser == null)
                {
                    throw new Exception("UserDoesNotExists");
                }
                role = dbUser.userrole;
            }
            return(role);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Used for the Login to verify if a "User" is qualified.
        /// It checks Email, password and if the Useraccount is activ.
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns>bool AuthUser</returns>
        public static bool AuthUser(string email, string password)
        {
            try
            {
                string dbUserPassword = null;
                string dbUserSalt     = null;

                using (var db = new ClonestoneFSEntities())
                {
                    tblperson dbUser = db.tblperson.Where(u => u.email == email).FirstOrDefault();
                    if (dbUser == null)
                    {
                        throw new Exception("UserDoesNotExist");
                    }

                    dbUserPassword = dbUser.password;
                    dbUserSalt     = dbUser.salt;

                    Log.Writer.LogInfo("Entered Pass = "******"HashPass = "******"Wrong pass");
                    }

                    if (dbUser.isactive == true)
                    {
                        return(true);
                    }

                    else
                    {
                        throw new Exception("User is not Active");
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Used for Registration to check if the used Email is allready in use.
        /// </summary>
        /// <param name="email"></param>
        /// <returns>bool CheckIfEmailIsUnique</returns>
        public static bool CheckIfEmailIsUnique(string email)
        {
            tblperson pers = new tblperson();

            using (var db = new ClonestoneFSEntities())
            {
                pers = (from u in db.tblperson
                        where u.email == email
                        select u).FirstOrDefault();
            }

            if (pers == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// get User basedon email adress
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static tblperson GetUserByUserEmail(string email)
        {
            tblperson dbUser = null;

            try
            {
                using (var db = new ClonestoneFSEntities())
                {
                    dbUser = db.tblperson.Where(u => u.email == email).FirstOrDefault();
                    if (dbUser == null)
                    {
                        throw new Exception("UserDoesNotExists");
                    }
                }
            }
            catch (Exception e)
            {
                Log.Writer.LogError(e);
            }
            return(dbUser);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Used to execute and confirm orders (card- and goldorders)
        /// Cardorder: checks if user has enough currency then generates the amount of cards based on cardquantity
        /// Goldorder: creditcard payment, creditcardnumber get checkt via luhn algorithm and data will be send via HTTPS to the Credit Card company
        /// </summary>
        /// <param name="personID"></param>
        /// <param name="packID"></param>
        /// <param name="creditCardNumber"></param>
        public static void ExecuteOrder(int personID, int packID, string creditCardNumber)
        {
            using (var db = new ClonestoneFSEntities())
            {
                tblorder      order = new tblorder();
                tblcollection col   = new tblcollection();
                Random        r     = new Random();

                order.fkpack    = packID;
                order.fkperson  = personID;
                order.orderdate = DateTime.Now;
                db.tblorder.Add(order);
                db.SaveChanges();

                int orderID = (from p in db.tblorder
                               orderby p.idorder descending
                               select p.idorder).FirstOrDefault();

                int cardq = (from q in db.tblpack
                             where q.idpack == packID
                             select q.cardquantity).FirstOrDefault();

                #region Kartenpacks
                if (cardq != 0)
                {
                    // Update Person !
                    try
                    {
                        var updatePerson = (from p in db.tblperson
                                            where p.idperson == personID
                                            select p);

                        var packValue = (from v in db.tblpack
                                         where v.idpack == packID
                                         select v.packprice).FirstOrDefault();

                        foreach (var value in updatePerson)
                        {
                            value.currencybalance -= (int)packValue;
                        }
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Log.Writer.LogError(e);
                    }

                    // Insert Cards !
                    for (int i = 0; i < cardq; i++)
                    {
                        int rng  = r.Next(1, 698);
                        var card = (from c in db.tblcard
                                    where c.idcard == rng
                                    select c).FirstOrDefault();

                        if (card != null)
                        {
                            col.fkperson = personID;
                            col.fkorder  = orderID;
                            col.fkcard   = card.idcard;

                            db.tblcollection.Add(col);
                            db.SaveChanges();
                        }
                        else
                        {
                            i = i - 1;
                        }
                    }
                }
                #endregion

                #region Goldpacks
                else
                {
                    //TODO - ausbessern
                    if (true)
                    {
                        tblperson person       = new tblperson();
                        var       updatePerson = (from p in db.tblperson
                                                  where p.idperson == personID
                                                  select p);

                        var goldValue = (from g in db.tblpack
                                         where g.idpack == packID
                                         select g.goldquantity).FirstOrDefault();

                        foreach (var value in updatePerson)
                        {
                            value.currencybalance += (int)goldValue;
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        //was auch immer
                    }
                }
                #endregion
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Whole logic for register,
        /// Generates Hashed Pass and Salt, generates 3 decks for the User, sends a confirmation Mail to the User
        /// and saves everything to the Database
        /// </summary>
        /// <param name="regUser"></param>
        /// <returns>bool named register</returns>
        public static bool Register(tblperson regUser)
        {
            try
            {
                using (var db = new ClonestoneFSEntities())
                {
                    if (db.tblperson.Any(n => n.email == regUser.email))
                    {
                        throw new Exception("UserAlreadyExists");
                    }
                    //Salt erzeugen
                    string salt = Helper.GenerateSalt();

                    //Passwort Hashen
                    string hashedAndSaltedPassword = Helper.GenerateHash(regUser.password + salt);

                    regUser.password = hashedAndSaltedPassword;
                    regUser.salt     = salt;

                    db.tblperson.Add(regUser);
                    db.SaveChanges();

                    //Decks Speichern
                    tbldeck deck = new tbldeck();
                    deck.deckname = "Mage";
                    deck.fkperson = regUser.idperson;
                    db.tbldeck.Add(deck);

                    tbldeck deck1 = new tbldeck();
                    deck1.deckname = "Hunter";
                    deck1.fkperson = regUser.idperson;
                    db.tbldeck.Add(deck1);

                    tbldeck deck2 = new tbldeck();
                    deck2.deckname = "Rogue";
                    deck2.fkperson = regUser.idperson;
                    db.tbldeck.Add(deck2);

                    db.SaveChanges();

                    //TODO - Email Einstellungen korregieren!!!
                    //try
                    //{
                    //    SmtpClient client = new SmtpClient("mail.gmx.net");
                    //    client.Credentials = new NetworkCredential("*****@*****.**", "123user!");
                    //    client.Port = 465;
                    //    client.EnableSsl = true;

                    //    MailMessage mess = new MailMessage();
                    //    mess.From = new MailAddress("*****@*****.**");
                    //    mess.To.Add($"{regUser.email}");
                    //    mess.Subject = "Registration confirmation!";
                    //    mess.Body = "Welcome to Clonestone, thank you for your registration. As gift you got 1000 Gold from us to start. Have fun!";

                    //    client.Send(mess);
                    //}
                    //catch (Exception e)
                    //{
                    //    Debug.WriteLine(e.Message);

                    //}
                }
            }
            catch (Exception e)
            {
                throw;
                //Writer.LogError(e);
            }

            return(true);
        }