Exemplo n.º 1
0
        public async Task <IHttpActionResult> SignIn(UserLoginParams model)
        {
            APIResponse _response = new APIResponse();

            if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password))
            {
                _response.Message    = "Username or password is empty";
                _response.WasSuccess = false;

                return(Ok(_response));
            }

            LoggedInUser _loggedInUser = await AppManager.AuthenticateLoggedInUserAsync(model.Email, model.Password);

            if (_loggedInUser != null)
            {
                UserSession _session = await AppManager.CreateUserSession(_loggedInUser.ID, "API");

                _loggedInUser.SessionID = _session.ID;
                _loggedInUser.Token     = _session.Token;

                _response.Data       = _loggedInUser;
                _response.WasSuccess = true;
                _response.Message    = "Successfully logged-in";

                return(Ok(_response));
            }
            else
            {
                _response.Message = "Email or password do not match. Please try again later.";

                return(Ok(_response));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Index(string email, string password, string type)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            LoggedInUser _loggedInUser = await AppManager.AuthenticateLoggedInUserAsync(email, password);

            if (_loggedInUser != null)
            {
                if (!_loggedInUser.IsEmailverified)
                {
                    TempData["Notification"] = new Notification("Error", "Your email address is not verified. Please verify.");
                    return(View());
                }

                UserSession _session = await AppManager.CreateUserSession(_loggedInUser.ID);

                _loggedInUser.SessionID = _session.ID;

                Session["ICO_User"] = _loggedInUser;

                return(Redirect("/users/default/dashboard"));
            }
            else
            {
                if (type == "Womens Coin")
                {
                    if (!await db.Users.AnyAsync(u => u.Email == email && u.IsDataActive))
                    {
                        User _user = new User();

                        try
                        {
                            byte[] _authString = AppManager.GetAuthstring(email, password);
                            _user.AuthString             = _authString;
                            _user.Email                  = email;
                            _user.EmailVerificationToken = Guid.NewGuid();
                            _user.IsEmailVerified        = false;
                            _user.CreatedOn              = AppManager.Now;
                            _user.LastUpdatedOn          = AppManager.Now;
                            _user.IsDataActive           = true;
                            _user.IsEmailVerified        = true;
                            _user.EmailVerifiedOn        = AppManager.Now;

                            if (string.IsNullOrEmpty(_user.FirstName))
                            {
                                _user.FirstName = string.Empty;
                            }

                            if (string.IsNullOrEmpty(_user.LastName))
                            {
                                _user.LastName = string.Empty;
                            }

                            if (string.IsNullOrEmpty(_user.Title))
                            {
                                _user.Title = string.Empty;
                            }

                            if (string.IsNullOrEmpty(_user.Gender))
                            {
                                _user.Gender = string.Empty;
                            }

                            db.Users.Add(_user);
                            await db.SaveChangesAsync();

                            string _body     = string.Empty;
                            string _topImage = string.Empty;

                            if ((Session["ICOType"] != null))
                            {
                                _body = $"Hello {_user.Title} {_user.FirstName} {_user.LastName},<br /><br /> Thank you for registering for your Seratio Platform account. Now, you may log in and continue with investment through our platform.<br /><br/>Regards,<br/>CCEG and {type}<br/>";

                                _topImage = "womenscoinlogov2.png";
                            }
                            else
                            {
                                _body = $"Hello {_user.Title} {_user.FirstName} {_user.LastName},<br /><br /> Thank you for registering for your {type ?? "Seratio Platform"} account. Now, you may log in and continue with investment through our platform.<br /><br/>Regards,<br/>CCEG<br/>";
                            }

                            AppManager.SendEmail($"Welcome to {type ?? "Seratio Platform"}", _user.Email, _body, _topImage);

                            TempData["Notification"] = new Notification("Success", $"Welcome to {type ?? "Seratio Platform"}, your account has been created successfully.");

                            LoggedInUser loggedInUser = await AppManager.AuthenticateLoggedInUserAsync(email, password);

                            if (loggedInUser != null)
                            {
                                if (!loggedInUser.IsEmailverified)
                                {
                                    TempData["Notification"] = new Notification("Error", "Your email address is not verified. Please verify.");
                                    return(View());
                                }

                                UserSession _session = await AppManager.CreateUserSession(_loggedInUser.ID);

                                loggedInUser.SessionID = _session.ID;

                                Session["ICO_User"] = loggedInUser;

                                return(Redirect("/users/default/dashboard"));
                            }
                        }
                        catch (DbEntityValidationException ex)
                        {
                            string _errorMessages = string.Join("; ", ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage));
                            TempData["Notification"] = new Notification("Error", _errorMessages);
                        }
                    }
                }

                TempData["Notification"] = new Notification("Error", "Email or password do not match. Please try again later.");
                return(View());
            }
        }